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 /
This question was closed May 16, 2016 at 12:21 PM by scouTpX for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by scouTpX · May 16, 2016 at 05:44 AM · javascripttimevariables

Activate line just one time

Hi , I need help. How can I activate a line just one time , until the "if" changes , like a GetKeyDown but for vars, for example(JS);

 example: boolean;
 
 function Start () {
 example = true;
 }
 
 function Update () {
 if(example == true)
     {
     //I need this Log shows in the console just one time, until I change to false
     //And true later
     //Like press GetKeyDown to do only a thing each time
     Debug.Log("Just one time");
     }
 }

If I use this script, the Log repeats every time it is read. Probably this can be the easier question you'll see today, but I rlly need help!

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Nazirzadeh · May 16, 2016 at 05:58 AM

 Is this what you mean?
 
  if(example == true)
          {
          example=false;
          
         if( Input.GetKeyDown( KeyCode.Space ) )
          example=true;
          
          Debug.Log("Just one time");
          }
 
Comment
Add comment · Show 4 · 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 scouTpX · May 16, 2016 at 11:06 AM 0
Share

Not really, "Get$$anonymous$$eyDown" its only an example , because he play the next line just one time, here is the console when i play the first script (see the img), The Log is running all the time, i need just one,Today I´ve already thinked in other ways to solve my problm , like

 var example: boolean;
 var time: int;
 
 function Start () {
 example = false;
 time = 0;
 }
 
 function Update () {
 if(example == true)
     {
     // 1 - This int will increase
     time = time + 1;
     }
 else if(example == false)
     {
     //3.2 - Only a way to reset
      time = 0;
     }
 if(time == 1)
     {
     // 2 - This will happen until "time" is 1, in another update he will be two
     Debug.Log("Just one time");
     }
 else if(time > 3)
     {
     // 3.1 - This is only a way to reset
     example = false;
     }
 }

But if you meet any command that can simplify this script, will be very helpful, i'm sorry if you can't understand, I'm not american and my english scks.

![alt text][1] [1]: /storage/temp/70171-screenshot-1.png

screenshot-1.png (25.7 kB)
avatar image Nazirzadeh scouTpX · May 16, 2016 at 12:17 PM 0
Share

Sorry but it is very bad coding style :)

  static var justOne:boolean=true;
     if(time == 1 && justOne==true)
          {
          justOne=false;
          Debug.Log("Just one time");
          }

You can set the justOne variable to false or true from the other scripts too, because its a static variable.

avatar image scouTpX Nazirzadeh · May 16, 2016 at 12:32 PM 0
Share

Sorry, I am very newbie in this area :p , but , tnks for the help!!

Show more comments

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Breathing sound effect using timers 1 Answer

How do i get attributes of another object? 1 Answer

Having a script variable update between two objects 1 Answer

Time.deltaTime not consistent over time 1 Answer

Let's Discuss Efficiency (Tags Vs Variables) 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