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 banana111 · Dec 13, 2014 at 04:10 PM · variablefloatreset

how to reset a float var

i want to reset my timer OnMouseDown thats it simple if any 1 could help me i would be very greatful tnx. here is the script:

var timer : float = 0;

var reset : float = 0;

var speed : float = 0.2;

function Update () {

 timer++;

 if(timer == 500)

 {

     this.transform.position.x -= this.speed;

 }


}

function OnMouseDown () {

 //here i would like to reset the var timer


}

i hope some 1 can help me

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 SkaredCreations · Dec 13, 2014 at 06:21 PM 0
Share

What does it mean "reset"? It's starting as 0, so just set it to 0 (timer = 0;). Anyway checking for timer until it's 500 in Update can produce unexpected results, since the framerate can potentially severely affects the number of times it's increased (it's not like "wait 500 milliseconds or 500 seconds" or anything like that).

2 Replies

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

Answer by Antony-Blackett · Dec 13, 2014 at 04:10 PM

 function OnMouseDown () { timer = 0; }
Comment
Add comment · Show 5 · 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 banana111 · Dec 13, 2014 at 04:14 PM 0
Share

i apiriciat the efort but it dosent realy work tnx any ways

avatar image Antony-Blackett · Dec 13, 2014 at 04:26 PM 0
Share

Then something else is going wrong cause setting a variable to 0 should be that simple. Put a Debug.Log("Am I working?" ); call inside that function and see if On$$anonymous$$ouseDown() is even being called.

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseDown.html

Does your object have a collider or GUIElement attached to it? Because the documents say you need that for On$$anonymous$$ouseDown() to be called.

avatar image banana111 · Dec 13, 2014 at 04:29 PM 0
Share

dude im so sory i just realized what was wrong im so sory there was a invis button blocking The way so i couldent press the gameobject whit the script tnx for the answer thank you and im so sory and realy greatfull thank you.

avatar image Antony-Blackett · Dec 13, 2014 at 04:31 PM 0
Share

No problem

avatar image banana111 · Dec 13, 2014 at 04:34 PM 0
Share

tnx again helpd me realy (im a bigginer if you couldent tell alredy)

avatar image
0

Answer by Ericool · Dec 14, 2014 at 09:06 AM

Usually ++ is for an integer. Secondly , what you want to do is moving around a gameObject so use a simple state machine : if(transform.position < 0.0f) state = goright; else if(transform.position > 500.0f) state = goleft;

       if(state == goleft) t = 1.0f;
       else t = -1.0f;

       transform.position += t * Time.deltaTime * (Vector.right);

something like that.

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 Reset Variable After Loop 1 Answer

How do I make my own Remote Settings backend like Unity Analytics Remote Settings? 0 Answers

I have a variable that does not re-set on the closing of my program, the variable is modified on the trigger enter, why does it not re-set? 0 Answers

How could I convert the y axis in a Vector 3 into a float? 1 Answer

Public Variable not updating 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