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 Asukakitti09 · Oct 09, 2013 at 08:26 PM · statements

plz help how do i script/code this line

Hi I'm new to Unity, I'm having a problem with writing a line of code. I need to write If x amount of seconds have passed, move GUItext to the bottom right corner. A little stuck on how I should go about writing it. Any ideas or help of what I should do would be much appreciated.

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
0

Answer by MarkD · Oct 09, 2013 at 08:36 PM

This is very easy so you will catch up quick :) Lucky for GUI coding is that OnGUI() supports coroutines (timing)

so you could for instance write

 //This will be telling the button's position
 var Position:Vector2(ScreenWidth,ScreenHeight);
 
 function OnGUI(){
 If(GUI.Button ("name")Position){
 your function or anything;
 }
 
 yield WaitForSeconds (Amount of seconds goes here);
 
 //and when the time has passed here we will change the coördinates of the Position variable
 Position = Vector2(ScreenWidth,ScreenHeight);
 
 
 
 }


Now this script is probably not correct because I just made it here on the fly, but it does follow the same principle you must handle to do what you are anticipating.

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 robertbu · Oct 09, 2013 at 08:49 PM 0
Share

@$$anonymous$$arkD - You don't want to do a yield in a OnGUI like this. You will stack up a coroutine every time OnGUI() is called (which is multiple times a frame). GUI elements use Rects to position elements, not a Vector2s (and the parameters are not syntactically correct in your GUI.Button() call). GUI elements are anchored in the upper left corner, so your position of ScreenWidth and ScreenHeight would place the button off the screen (and your initialization is not syntactically correct). Finally he is asking about GUIText, which is not a GUI element. Not sure if he really means GUIText or if he means GUI.Label(), but he is asking for GUIText.

I know it is not always convenient or possible, but consider running a brief test on the code you propose as a solution.

avatar image MarkD · Oct 10, 2013 at 07:46 PM 0
Share

@robertbu, you are 100% correct, like i said I made it on the fly, I did not take time to test it, but I have used yield in multiple occasions within the GUI and never seemed to have a problem with it. Ofcourse those where small applications, maybe in an application that uses more resources it could indeed be negative.

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

Stop Script Completely. Doesn't Execute Another Line Of Code. 1 Answer

Having problems with my timer 1 Answer

Teleporter 2 Answers

This code crashes unity, please help! 0 Answers

problem with my simple script please help. 2 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