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 Robert Ahearne · May 18, 2016 at 07:23 AM · javascriptcollisiontimer countdown

How can I update timer using a collision?

I have a empty game object called Clock with this script attached, I want to try and add time when I collid into another game object.

 var timer : float = 10.0; //Create varable Timer of type float
 
 function Update () 
 {
     timer -= Time.deltaTime;//Varable time decrements from set value (10.0)
     if(timer <= 0)//When timer = 0
         {
             timer = 0;
             Application.LoadLevel(6);//loads the game over scene
         }
 }
 
 function OnGUI ()
 {
      GameObject.Find("TimerText").GetComponent.<UI.Text>().text="Timer:" + timer.ToString("0");
 }

My Second script is on the game object I want to collid with once I hit this it should update the timer but I cant figure out where Im going wrong

 import UnityEngine.UI;
 
 
 
 function OnTriggerEnter (info:Collider)//when trigger enters 
 {
     var pickUpAudio : AudioSource = GetComponent.<AudioSource>();
     pickUpAudio.Play ();
     //Timer.timer +=10;/
     transform.position = Vector3(0,-1000,0);
     yield WaitForSeconds (1.5);
     Destroy (gameObject);/
 
 }




Comment
Add comment · Show 4
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 vittu1994 · May 18, 2016 at 07:49 AM 0
Share

What results are you getting with your code? Does Timer.timer += 10 work? Does it add time but not in the way you want to? Do you want to reset the timer with colliding or just add a portion of time to it?

avatar image Robert Ahearne vittu1994 · May 18, 2016 at 11:57 AM 0
Share

I'm trying to add time by 10seconds each time theres a collision. it doesnt add time but the countdown is working fine. Im confused :(

avatar image HarshadK · May 18, 2016 at 10:24 AM 0
Share

You need to get a reference to your Timer script component and then access timer variable to add time to it.

avatar image Robert Ahearne HarshadK · May 18, 2016 at 11:56 AM 0
Share

Hi Harshadk, what do you mean by reference my Timer? Is Timer.timer +=10; a refernce to it? Thanks

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by arbazgillani · May 18, 2016 at 02:12 PM

Start a coruotine of 10 seconds and add time.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make one object pass through one object but hit another? 2 Answers

Destroy Object on Collision (with di sound) 0 Answers

How to raycast object as far as possible, without collision? 0 Answers

Multiplayer 2 Answers

How to change bullet on impact? 3 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