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 steelesound · Oct 18, 2014 at 10:03 AM · colliderinputtriggerinput.getkeycooldown

How can I synchronize the cooldown on two separate scripts?

I've got a script setup to turn particle effects on for an ability, play for specified ability time and then go on cool down. Now one of my abilities is triggering a particle effect on my player as well as on another object.

I have it setup so that when the player is in the object's collider the specified key will turn the particles on. This all works fine except when I used the ability outside of the collider. In this case, the player's particles will turn on which is what I want, but then if I move into the collider and use the ability again it will trigger only that objects particles.

Problem is essentially that both sets of particles need to be on cooldown at the same time, regardless of if my player is in the collider to trigger the objects set of particles.

I'd actually like to find a way that I could just put my "fire2" input itself on cooldown for X Seconds globally but haven't figured that out either.

This is the script on my non player object:

 #pragma strict
  
 var MobisPlaying = false;
 var MobcoolDown = 1.5;
 
 
 
 
 function OnTriggerStay (other : Collider) {
 if (!MobisPlaying && Input.GetButtonUp("Fire2")) {
 PlayMPS();
     }
 }
 
 
  
 function PlayMPS() {
     MobisPlaying = true;
     particleSystem.Play();
     yield WaitForSeconds(0.5);
     particleSystem.Stop();
     yield WaitForSeconds(MobcoolDown);
     MobisPlaying = false;
  }




This is what is on my player:

 #pragma strict
  
 var isPlaying = false;
 var coolDown = 1.5;
 
 
 function Update() {
     if (!isPlaying && Input.GetButtonUp("Fire2")) {
         PlayPS();
 
     }
 }
  
 function PlayPS() {
     isPlaying = true;
     particleSystem.Play();
     yield WaitForSeconds(0.5);
     particleSystem.Stop();
     yield WaitForSeconds(coolDown);
     isPlaying = false;
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FreeTimeDev · Oct 18, 2014 at 12:51 PM

If you wanted to make the input have a cooldown globally because of it being used so much you'd probably want to make a static boolean associated with it on the player script.

Make a static boolean (CanFire2) When the input is pressed, on the player script, check to see if they CanFire2 if yes, set it to false and make a timer if no, do nothing on all other scripts you will easily be able to access CanFire2 because it's static. You don't have to check for inputs, you'd just check for the state of CanFire2.

I have a hunch there's a better way to do what you want, but I learned to do things (sometimes the wrong way!) a little out of the ordinary. And if it works...it works.

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
avatar image
0

Answer by steelesound · Oct 19, 2014 at 06:04 AM

I understand the concept of what you're saying and I think it's going to accomplish what I'm looking for. I'm not quite sure how to lay that out in code though, would you mind elaborating on it a bit?

Sorry, I am indeed very new and most of the scripts I have put together are based off of what I can find here. I'm not so good at writing them from scratch.

For the player script, I have something like this and I don't quite think I'm on the right track:

pragma strict

  var canFire2 : boolean = false;
 
 
 
 function Update() {
     if (Input.GetButtonDown("Fire2")) {
         PlayCanFire2();
     }
 }
  
 function PlayCanFire2() {
     canFire2 = true;
     yield WaitForSeconds(12.0);
     canFire2 = false;
 }
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

Interacting with a button by colliding with it 1 Answer

Can't click gameobject when over another trigger? 1 Answer

detect Collision/Trigger seperately for more than one collider in one gameObject 0 Answers

Input keycode string not working 2 Answers

Trigger collider triggers even though colliders are not touching 2 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