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 Suraj. · Feb 09, 2015 at 12:47 PM · timerpowerup

magnetic Powerup Timer Problem

Hi there. I need help. I have one magnetic powerup in game after picking it up...player will start attracting coins ... And after sometime efffect will go off.Its all working fine. But in one scene it works only for first magnetic powerup..not the next one. Please help.

Here is my script which is put on coin..there is one bool in script which is attached to magnetic powerup icon(to be picked in game).this bool becomes true when player collides.bool is magneticeffect

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class Coins_Magnet : MonoBehaviour {

 public GameObject char2d;
 public static int PlayerScore = 0;
 int ScoreInc = 10;
 public GameObject Coin;
 public AudioClip CoinPickupSound;
 public static float timeLimit = 10.0f;

 void Start(){
     
 }

 void Awake()
 {
 }
 void Update ()
 {
     if(Vector3.Distance(transform.position, char2d.transform.position) < 5 && MagnetPU.PUEffect == true && timeLimit > 0){

             timeLimit -=Time.deltaTime;
             transform.position = Vector3.MoveTowards(transform.position, char2d.transform.position, Time.deltaTime *11);
     }

     if (timeLimit <0 ){
         MagnetPU.PUEffect = false;
     }
     
 }
 
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {            
         PlayerScore+=ScoreInc;
         Destroy(this.gameObject);
         if (Mute.clips == true){
         AudioSource.PlayClipAtPoint (CoinPickupSound, transform.position);
         }
     }
 }
 void OnDisable(){
     
     

} }

Comment
Add comment · Show 6
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 $$anonymous$$ · Feb 09, 2015 at 12:57 PM 0
Share

I think the problem is elsewhere in the scene.

avatar image Suraj. · Feb 09, 2015 at 01:02 PM 0
Share

I know the problem is second magnet is not getting more timeLimit. i need to add else condition..but its not working..getting more bugs

avatar image $$anonymous$$ · Feb 09, 2015 at 01:38 PM 0
Share

After a certain amount of time try suspending all operations on one magnet and reseting the timer and use in another magnet and so on.

avatar image meat5000 ♦ · Feb 09, 2015 at 02:05 PM 0
Share

And they are identical? The first and second powerups?

avatar image Suraj. · Feb 09, 2015 at 02:29 PM 0
Share

thanks all for ur response... Yes meat5000 both powerups are identical.i have checked it many times. Nimish I am having problem with resetting the timer. Because else is not working. This is the only part remaining in my game. I am so frustrated.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Tarondar · Feb 09, 2015 at 04:12 PM

Hi,

I think it could solve the problem if you change the code like this:

 if (timeLimit <0 ){
 MagnetPU.PUEffect = false;
 timeLimit = 10.0f; // this line resets the timeLimit instantly when the effect ends
 }

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 $$anonymous$$ · Feb 09, 2015 at 04:24 PM 0
Share

I think the timer should reset when timeLimit will be 0f.

avatar image Suraj. · Feb 10, 2015 at 04:37 AM 0
Share

Tarondar..thank u so much man....I was so stupid not to get that. Thanks a lot man.

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

21 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

Related Questions

Trying to Create a Powerup that lasts a certain amount of time 1 Answer

Deactivating a power up script after a certain amount of time 1 Answer

How to make a loop for PowerUps/Bonus 2 Answers

Powerup Timer not Working 3 Answers

Bug? And any way to do something for 5 seconds when shift is held? 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