Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jsquiz82 · Oct 14, 2011 at 08:56 PM · guiguitext

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);

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ashiren · Dec 07, 2011 at 10:00 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Not working gui buttons 1 Answer

Random spawning papers, plus GUI texture book help. 0 Answers

Gui text, ammo counter 1 Answer

No GUI needed..!!! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges