Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tachikoma · Jun 28, 2011 at 08:09 AM · particlesmuzzleflash

muzzle flash and particle emit didn't show when shot

Here is my code, I attached this to the launcher position.And drag the mesh and particle to the slot. But anything happened when shot. Also ,I don't understand " enabled = false" usage in function lateupdate(), may be confused with "muzzleFlash.enabled = false;" but when I deleted "enabled= false",I can see the muzzle flash. But particle still not been seen. Anyone can give help?

 var projectile :  Rigidbody;
 var speed = 150;
 var fireRate = 0.05;
 var damage = 5.0;
 var reloadTime = 5;
 var range = 1000;
 var bulletsPerClip = 30;
 var clips = 20;
 var muzzleFlash : Renderer;
 var nextFireTime = 0.0; 
 var m_LastFrameShot = -1;
 var hitParticles : ParticleEmitter;
 var force = 1;
 private var bulletsLeft;


 function Start()
 {

     bulletsLeft = bulletsPerClip;
     hitParticles = GetComponentInChildren(ParticleEmitter);
     if(hitParticles)
     {

         hitParticles.emit = false;
     }

 }




 function Update ()
 {


     if( Input.GetButton("Fire1")&&Time.time > nextFireTime)
     {
         nextFireTime = Time.time + fireRate;
         FireOneShot();
     }
 }



 function FireOneShot()
 {
     var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2));

     var hit : RaycastHit;
     var hit2: RaycastHit;
     var ourTarget : Collider;
     var direction;

     if(Physics.Raycast(ray,hit,range))
     {
         Debug.DrawLine( transform.position, hit.point, Color.red);

         Debug.Log(hit.point );   


         direction = (hit.point - transform.position).normalized;

         if (Physics.Raycast(transform.position,direction,hit2,range))
         {
             if (hit2.collider.tag == "Enemy")
                 hit2.collider.SendMessage("ApplyDamage",damage);


             if(hitParticles)
             {

                 print("hitparticle");
                 hitParticles.transform.position = hit.point;
                 hitParticles.transform.rotation =
                     Quaternion.FromToRotation( Vector3.up, hit.normal);
                 hitParticles.Emit();

             }

         }
     }


     bulletsLeft--;
     m_LastFrameShot = Time.frameCount;
     enabled = true;
     print(bulletsLeft);

     if(bulletsLeft ==0)

         Reload();



 }


 function LateUpdate()
 {
     if(muzzleFlash)

     {

         if (m_LastFrameShot == Time.frameCount)
         {
             muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.Range(0, 359), Vector3.forward);
             muzzleFlash.enabled = true;

         }


         else {
             muzzleFlash.enabled = false; 
             enabled = false; 
         }
     }
 }




 function Reload()
 {
     yield WaitForSeconds(reloadTime);
     if( clips > 0)
     {
         clips--;
         bulletsLeft = bulletsPerClip;
     }
     else
         print("You haven't enough ammo");
 }

 function GetBulletsLeft ()
 {
     return bulletsLeft;
 }

 function OnGUI()
 {
     GUI.Label(new Rect(Screen.width-128-100,228,200,128), "BulletLeft:" + bulletsLeft);


 }
Comment
Add comment · Show 1
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
avatar image flaviusxvii · Jun 28, 2011 at 05:02 PM 0
Share

I reformatted your code. Nicely formatted code gets more ANSWERS!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Alex 4 · Jun 28, 2011 at 06:16 PM

Do you have all variables assigned?

Comment
Add comment · Show 2 · 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
avatar image Chris D · Jun 28, 2011 at 07:06 PM 0
Share

Please don't post other questions or clarifications as an answer; the answer area should be for solutions to avoid clutter.

avatar image tachikoma · Jun 29, 2011 at 01:28 PM 0
Share

Yes,I added all, but they didn't show when I shot T T

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Gun Muzzle Flash Effect 0 Answers

Particle that spawn from the top (pole) of a sphere rather than center 3 Answers

How to move direction of particle(s) emitted by ParticleSystem Shuriken 2 Answers

Particle Velocity Decay/Slow Down? 1 Answer

Jetpack with other particles 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