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 decay · Mar 17, 2016 at 03:00 PM · javascriptguijava

Move Button as soon as its klicked to the bottom Screen

Hey guys,

so i have this task of moving a button to the bottom of the screen as soon as its clicked. i tired different solutions:

 var button : Texture;
 var x : int = 20;
 var bottom : int = (Screen.height - 20);
 var time : int = 2;
 var startTime : int = Time.time;
 var speed : int = 100;
 
 function OnGUI() {
     if (GUI.Button (Rect(10,x,80,40), button))
         Debug.Log("Es geht los!");
     //  x += 150*Time.deltaTime;    <<-- This way the button never stops to move
         
 }
 
 function Update() {                        <<-- this way the button stops at the middle of the screen (?)
 
     if(Time.time > startTime + time) {
         x += Time.deltaTime*speed;
         if (x > bottom) {
             x = bottom;
         }
     }
 }

but none of them really worked.

i need the button to go to the bottom of the screen, and then move to the top and back like 5 times.

thanks in advance!

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 Brocccoli · Mar 17, 2016 at 03:14 PM

I would set a boolean value on button click

 if (GUI.Button (Rect(10,x,80,40), button))
 {
   bool moveButton = true;
 }

Then in your Update method

 while(moveButton){
   // Increment button towards the bottom of the screen
   if (buttonAtDesiredPosition)
   {
     moveButton = false;
   }
 }

There's some sudo code to get you started. Get rid of the Time.Time and DeltaTime stuff, I don't think you need it.

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 decay · Mar 17, 2016 at 03:51 PM 0
Share

Thanks, loos like a simple yet useful structure. :) can you help me further and be a bit more specific about the actual moving and reaching the position?

avatar image Brocccoli decay · Mar 17, 2016 at 03:54 PM 0
Share

Seems like the logic you have more moving right now will do. You just need to know what your desired position is and that's when you stop.

avatar image decay Brocccoli · Mar 17, 2016 at 09:38 PM 0
Share

yeah but how can i check the position of the button? What would be the script line?

Show more comments

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

83 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

أنجازات غير مسبوقة؟؟!!توكيل كاريير +بالاسكندرية 01286629661 0 Answers

Can't add script behaviour TMP_CoroutineTween. The script needs to be derived from MonoBehaviour. I need help with this script. 0 Answers

JavaScript function OnGUI error 1 Answer

Ui button doesn"t disappear [JS] 0 Answers

Are TextFields in GUI.window generally uneditable? 0 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