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 /
  • Help Room /
avatar image
0
Question by JIME363 · Mar 04, 2017 at 12:08 PM · gunfiremuzzleflash

Adding muzzle flash to the gun....

I Want to add a muzzle flash to the gun the gun automatically fires if the gun aims on enemy......

 #pragma strict
      var Rounds : int;
      var Ammo : int;
      var Reloading : boolean;
      var MaxAmmo : int = 20;
      var theDammage = 100;
      var delay = 0.1;
      var timestamp = 0.0;
      var ReloadTime = 1.8;
      private var reloading : boolean = false;
       function Start()
      {
      GetComponent.<Animation>().Play("Idle",PlayMode.StopAll);
     %|-841674305_1|%
      function Update ()
       {
      var hit : RaycastHit;
      var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
      if(Rounds == 0 && Ammo == 0  )
      {
      return;
      }
      if (Ammo <= 0 && Rounds >= 0 )
      {
      Reloading = true;
      GetComponent.<Animation>().Play("Reload",PlayMode.StopAll);
      Reload();
      }
      else
      {
      if (timestamp <= Time.time && Physics.Raycast (ray, hit, 10) && Reloading == false)
      {
       timestamp = Time.time + delay;
       if(hit.collider.gameObject.tag == "Dobj")
       {
       Ammo--;
       GetComponent.<Animation>().Play("Fire",PlayMode.StopAll);
       GetComponent.<AudioSource>().Play();
       hit.transform.SendMessage("ApplyDammage", theDammage, SendMessageOptions.DontRequireReceiver);
      }
      }
      }
      }
      function Reload()
      {
      yield WaitForSeconds (1);
      if(Ammo == 0 && !Reloading)
      {
      Rounds --;
      Reloading = true;
      Ammo = MaxAmmo;
      }
      Reloading = false;
     }

thanks in advance.........I am not using particle renderer ...i am using A simple plane`

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 hexagonius · Mar 04, 2017 at 12:14 PM 0
Share

What's your question?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Mar 04, 2017 at 01:14 PM

what you could do is have a point light at the very front of the barrel as well as maybe a particle system. (Add a flare to make it realistic). Make them as children so they follow the barrel where ever it goes.

Since you seem quite knowledgeable in animation I'd suggest using an animation that turns the light on for a set amount of time meaning you would not need to turn off the light through script(Which would suck).. so then all you'd have to do is

GetComponentInChildren().Play("LightFlash");

Sorry my input isn't more code handy but since i have no clue what your setup is or do i use your programming language natively i can't help too much.

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

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding muzzle flash to the unity 0 Answers

fireRate javascript? 1 Answer

Having trouble getting fps gun(s) too shoot please help me out now 2 Answers

Ammo Script 0 Answers

STUCK! Firing a simple sphere from below the camera at crosshair in the centre of the screen, with or without raycast. 0 Answers


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