x


Display Bullets Left on Screen

Im trying to get my bullets left to display on my screen already went through fps tutorial but it seems to be no help for me. It shows up and inspecter view but i cant get it on the screen. here is what i got so far.

       var Range : float = 1000;

       var Force : float = 1000;

       var Clips : int = 20;

       var BulletPerClip : int    = 50;

       var ReloadTime : float = 3.3;

          var Damage : int   = 20;

         var BulletsLeft : int = 0;

          var shootTimer : float = 0;

          var shootCooler : float = 0.06;

          public var ShootAudio : AudioClip;

          public var ReloadAudio : AudioClip;


          var HitParticles : ParticleEmitter;

          var MuzzleFlash : ParticleEmitter;

              var MuzzleCooler : float = 0.06;

              var MuzzleFlashTimer : float = 0;

              var light1 : GameObject;          

              var light2 : GameObject;          

              var light3 : GameObject;

          var MuzzleSpeed : int = 200000;

              var KeyTimer : float = 0;

              var KeyCooler : float = 1;          

function Start (){

    BulletsLeft = BulletPerClip;

    MuzzleFlash.emit = false;

    HitParticles.emit = false;

}

function Update () {

if( KeyTimer > 0){

KeyTimer -= Time.deltaTime;

}


    if( KeyTimer < 0){

    KeyTimer = 0;

}

if( MuzzleFlashTimer > 0){

MuzzleFlashTimer -= Time.deltaTime;

MuzzleFlashShow();

}

if( MuzzleFlashTimer < 0){

MuzzleFlashTimer = 0;

}

if( shootTimer > 0){

       shootTimer -= Time.deltaTime;

       }

       if( shootTimer < 0){

         shootTimer = 0;  
       }

        if( KeyTimer == 0){
       if(Input.GetKey(KeyCode.F) && BulletsLeft){
       if( shootTimer == 0){




       PlayShootAudio();
         RayShoot();

         shootTimer = shootCooler;

         }

         if( MuzzleFlashTimer == 0){

          MuzzleFlashTimer = MuzzleCooler;

                    MuzzleFlashShow();

}

}

} }

function MuzzleFlashShow (){

if( MuzzleFlashTimer > 0){

    MuzzleFlash.emit = false;

       light1.active = false;
        light2.active = false;
         light3.active = false;

    }

    if( MuzzleFlashTimer == MuzzleCooler ){

       MuzzleFlash.transform.localRotation = Quaternion.AngleAxis( Random.value * 360 * MuzzleSpeed , Vector3.forward);

    MuzzleFlash.emit = true;

       light1.active = true;
        light2.active = true;
         light3.active = true;



    }

}

function RayShoot (){

GameObject.Find("FPS_m16_01").animation.Play("m16_fire");
    var Hit : RaycastHit;

         var DirectionRay = transform.TransformDirection(Vector3.forward);

         Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);

         if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){


         if(Hit.rigidbody){


         if( HitParticles){

         HitParticles.transform.position = Hit.point;
         HitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, Hit.normal);
         HitParticles.Emit();


         Hit.rigidbody.AddForceAtPosition( DirectionRay * Force , Hit.point);
         Hit.collider.SendMessageUpwards("ApplyDamage" , Damage , SendMessageOptions.DontRequireReceiver);
         }
         }
         }

         BulletsLeft --;

         if(BulletsLeft < 0){

         BulletsLeft = 0;

         }

         if(BulletsLeft == 0 ){

         Reload();

         }

         }

function Reload (){

    PlayReloadAudio();
GameObject.Find("FPS_m16_01").animation.Play("m16_reload");
yield WaitForSeconds( ReloadTime);

       if(Clips > 0){

         BulletsLeft = BulletPerClip; 

} }

function PlayShootAudio(){

    audio.PlayOneShot( ShootAudio);

}

function PlayReloadAudio(){

audio.PlayOneShot( ReloadAudio);

}

more ▼

asked Oct 14 '11 at 08:56 PM

jsquiz82 gravatar image

jsquiz82
1 5 6 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

I'm also doing the FPS tutorial and my bullets were not showing up. I'm not sure if this fix will fix your problem, but it's worth a shot.

Check to ensure that the Particle Renderer is checkmarked under the spark object. If you want to get rid of the rendering of the particles, remove the checkmark for the Ellipsoid Particle Emitter so it won't show up in the editor.

more ▼

answered Dec 07 '11 at 10:00 AM

ashiren gravatar image

ashiren
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x2057
x884
x319

asked: Oct 14 '11 at 08:56 PM

Seen: 513 times

Last Updated: Dec 07 '11 at 10:00 AM