- Home /
Move GUI elements.
Ok so i have a GUITexture which i placed in the scene using it's transform component(not the Pixel Inset), and I have also placed a button in the scene via script(GUI.Button(Rect,"Button")). What I want to do is to move those elements when the left mouse button is pressed. I move the button updating it's y rect position, and i am moving the guitexture using its y component of the transorm, but they are not moved with the same amount: the guitexture moves more, while the gui button move less. What should i do to move those two elements with the same amount? Thank you and sorry for bad english :D
public Rect ButtonRect = new Rect(100,100,600,70);
public GUITexture image = null; //asign it via inspector.
void OnGUI()
{
GUI.Button(ButtonRect,"$$anonymous$$yButton");
if(Input.Get$$anonymous$$ouseButton(0) //move the button and the guitexture
{
ButtonRect.y = $$anonymous$$athf.$$anonymous$$oveTowards(ButtonRect.y,300,10);
image.transform.position = new Vector3(image.transform.position.x,
y-0.2f, image.transform.position.z);
}
}
This was what i've tryied so far but without success.
Your answer
Follow this Question
Related Questions
Animate GUI Elements 1 Answer
Convert GUI Button to GUI Texture 0 Answers
Tic Tac Toe beginner 0 Answers
How to draw GUI texture under UI elements? 0 Answers
How do I set up a GUITexture as a button? (Java Script) 2 Answers