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 Inan-Evin · Jul 24, 2013 at 10:08 AM · lerpmovelabel

Lerping the GUI, problem with doing it again

Hello everyone. I wanted to make a gui for my mission objective. What I wanted was a label from top would come in the middle of the screen with duration. ( our objective would be written on it ) Then wait a bit, and then go back to the very top of the screen and disappear. I accomplished this, but when I try to change the string and make it go middle of the screen again, it does not lerp again. Let me show you ;

     private var startX: float;
     private var endY: float;
     private var startTime: float;
     private var endTime: float;
     static var down : boolean;
     var duration: float;
 ``  var duration2: float;
     var myString : String;
     var w = 500;
     var h = 42;
 
 
 
         function Start() {
         
         down=true; 
     `  `startX = Screen.width/2 -180; // we dont need to deal with this, this is my desired location for x .
         endY = Screen.height /2 - Screen.height / 4;
         startTime = Time.time;
         yield WaitForSeconds(duration+1.7); // wait for it to go top again
         endTime = Time.time;
         down=false;
         }
     
     function OnGUI() {
     
     // styles and other vars
     
     
     
     var fracTime = (Time.time - startTime) / duration;
     var fracTime2 = (Time.time - endTime) / duration2;
     var yPos = Mathf.Lerp(1, endY, fracTime); // endY is the position which I want the label the go for, it'a bit upper than the middle of the screen.
     var yPos2 = Mathf.Lerp(endY, -1000, fracTime2); // for going back I used this
     var rect = Rect(startX,yPos, w, h); // startX is screen width /2 we dont have anything to do with it.
     var rect2 = Rect(startX,yPos2, w, h);  // for going back which uses yPos2
     
     
     if(down) // this is true at start, after 2 seconds this becomes false so the label go back.
     {
     GUI.Label(rect, myString,styleObjective);
     
     }
     if(!down)
     {
     GUI.Label(rect2, myString,styleObjective);
     }
     
         
     }

Now you see the script, player spawns, I make down = true at the start. Label goes down, waits, and goes back everythings alright. Then in another script, when player reaches somewhere, I change the myString value it's okay, and make "down" value true again. But it does not work as the first one. The label just appears is the endY pos, does not lerp. I think problem is about lerping.

Any ideas ? Thanks :)

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

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

Answer by Jamora · Jul 24, 2013 at 10:31 AM

Merely setting down = true is not enough, because you do all your initialization in Start(). To get this to work, you need to call StartCoroutine(*refrenceToTheScript*.Start()) (or just StartCoroutine(Start()) if you call it from the same script) instead of *scriptname*.down = true. There are lots of ways to get a refrence to your script... the easiest (to explain), yet not efficient, is to use GameObject.Find to find the gameobject, then get the refrence with GetComponent

EDIT: On second thought, Unityscript doesn't require StartCoroutine(), so you can just call Start normally. Also, I hope you have a copy-paste mishap in your snipppet: your two ifs at the end are exactly the same. I think one of them needs rect2.

Comment
Add comment · Show 1 · 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 Inan-Evin · Jul 24, 2013 at 11:18 AM 0
Share

yes I had problem about copy paste it's supposed to be rect2. And thank you it works I used send message, thanks a lot for the advice :).

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

16 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

Related Questions

How do i repeat the Lerp movement? 1 Answer

Move child gameobject in x axis (Lerp) 1 Answer

How can I find the velocity on a rigidbody which moves using Lerp? 1 Answer

Lerp a Object along X and Z axis only. 3 Answers

Vector3.lerp doesn't work 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