Change button position using script
Hi guys, I am creating a quizz and i dont know how to change position of button. I want to do this because i dont want that answer which are displayed on button shows always in the same order. So can you give me an example of how change 2 Button position for example we have ButtonAnswer1 ButtonAnswer2 and ButtonChangePosition. What i want is when you click on ButtonChangePosition the position of ButtonAnswer1 change with the position of ButtonAnswer2.
Ps:I know i have to use Vector and i saw in other post they write a code "Rect" but i dont know how to use those command and the documentation doesn't help me so please don't send me a link to a tutorial , if you can just show me the code for the example i give to you it would be very nice and it will help me alot . #thanks #HaveAniceDay #SorryForMyBadEnglish
Answer by Magius96 · Mar 02, 2016 at 05:24 PM
I have a better idea. Instead of changing the positions of the buttons, why not change the values that the buttons represent? From what I read of your question it sounds like you are really just trying to swap the buttons, which can be easier done by swapping what they represent instead.
That is unless you are hard coding the buttons, which is what it sounds like you are doing. In which case have to pose the question, "Can you think of no better way?"
Moving Buttons
Remember that the buttons are GameObjects, and every gameobject has a position vector in its transform. So if your button is named ButtonA, then in your code you want to get a reference to that.
GameObject buttonA = GameObject.Find("ButtonA");
Once you have a reference to the button, you can proceed in moving it. So let's imagine that we want to move ButtonA 10 units left.
Vector3 pos = buttonA.transform.position;
pos.X -= 10f;
buttonA.transform.position = pos;
how to change the text on button ... i have 8 buttons and 1 buttons will have the answer of a question ... i want to change the position but not changing on which way i want to ... now how to change that text
Answer by danidu93 · Mar 02, 2016 at 05:57 PM
Wow thank you very much for your answer your explication is very very good about how to move button . I already tryed to think another ways as you said.But it didnt works . Value of button every time changed but when i clicked on them it always show me "Wrong" (becaus i also have a hidden text which is enable when you press on a button and it show "True" if the answer is good or "Wrong" if not.Code was also very long and i get lost :/
Your answer
Follow this Question
Related Questions
Need to Change this script function , please 0 Answers
Could someone translate these to c#? 1 Answer
Having transitions between two VideoPlayers triggered by clicking "x" times in a text layer 0 Answers
How to convert string to runnable code? 0 Answers
How to enable and disable back game object for ui button after a few seconds? 1 Answer