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 AnselmeUnity · Dec 27, 2018 at 11:46 AM · gameobjectsetactiveactivation

Need to activate and deactivate objects really fast, doesn't work

Hello,

In order to do a muzzle flash effect for my FPS, I need to activate a parent gameobject that contains two muzzle textures and a spotlight and deactivate it just after in a very short period of time. So that it gives this "flash" effect.

The problem is that sometimes when I fire no muzzleflash appear, or only one of the two, etc. It's like the period of time is too short for the engine to activate all it has to.

So I don't know how to do this muzzleflash effect. The only solution I found is too increase the period of time but when the muzzle stays 0.5s at the screen it's way too long...

Here is my activation/deactivation code :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WeaponRecoil : MonoBehaviour {
     
     public float muzzleDuration = 0.1f;
     public GameObject muzzFlashes;
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetMouseButtonDown(0)) {
             muzzFlashes.SetActive(true);
             StartCoroutine(deactivateMuzzle());
         }
     }
     
     IEnumerator deactivateMuzzle()
      {
  
          yield return new WaitForSeconds(muzzleDuration);
 
          muzzFlashes.SetActive(false);
      }
 
 }

Thank you.

Comment
Add comment · Show 3
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 mlnczk · Dec 27, 2018 at 12:17 PM 1
Share

Just try doing animation and set it as trigger. While animating you will be able to set values as you want and speed how fast to animate. It doesnt work since you are using WaitForSeconds and 0.1f second is just too little to make it work. You can also test with WaitForEndOfFrame

avatar image AnselmeUnity mlnczk · Dec 27, 2018 at 02:14 PM 0
Share

Thank you for your answer. I just tried to animate and that seems a wonderful idea. Thanks !!

avatar image mlnczk AnselmeUnity · Dec 27, 2018 at 02:36 PM 0
Share

Glad to help. If it really helped you in this situation then mark my answer as correct please so people looking for similar problems find their answers.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vega4Life · Dec 27, 2018 at 02:20 PM

I think disabling the particle isn't the right way to handle this situation (or any particle for the most part). One of the reasons why is what you are encountering now - trying to time it correctly with an outside timer. This goes against the particle having its own timers, etc. The other reason is because if you just disable a particle, its an instant stop. Most times this looks really silly. Imagine disabling a fire particle - it won't look realistic. In those cases you would want to disable the emissions so it lets the current alive particles finish


I have a game that uses a muzzle flash also. It isn't tied with any outside timers or fire rates of my weapons. The most important thing is I just reset and play the particle when the weapon is fire. Using below:


         // This is called every time I shoot
         public void EnableFX(bool enable)
         {
             if (enable)
             {
                 particle.Clear();     // This essentially resets the particle
                 particle.Play();      // This plays particle
             }
         }


You just need a reference to the particle and the above works. You don't need a timer or anything like that. The particle will always play, but can interrupt itself (which is fine if a weapon is firing super fast).alt text I'll also post an image of my particle settings. The important thing on it is the simulation speed. Mine is set to 2, so that I get a super fast particle. Hope this info helps, good luck.



particle.png (15.4 kB)
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

145 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 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

one button to hide and unihed gameobjects 0 Answers

GameObjects that I deactivate are reactivated immediately 0 Answers

c# Set Active error, conflicting with other code.. 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Panel GameObject not activating 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