- Home /
How to move a texture created from GUI.DrawTexture
Hi everyone !
Just as the title says, I'm having problems moving a Ship Texture on the screen. Normally for game objects, we can use Vector3.Lerp(). However, I think this method doesn't work for textures in 2D. So, is there any way this can be done ? Thanks a lot in advance !
Answer by HarshadK · Apr 24, 2014 at 01:42 PM
You can do this using Vector3.Lerp.
You can set two Vector3 for startPosition and endPosition. For this startPosition and endPosition set z value to be zero.
Then you can lerp between these two Vector3 values.
You can then provide values of your new position achieved after Vector3.lerp to the rectangle of your GUI.DrawTexture as newPos.x and newPos.y for x and y position of the rectangle.
Here's is a script that moves a GUI.Button but you can use the same for GUI.DrawTexture.
Vector3 startPos = new Vector3(10,10,0);
Vector3 endPos = new Vector3(200,200,0);
Vector3 pos = new Vector3();
float damping = 1f;
void OnGUI() {
pos = Vector3.Lerp(startPos, endPos, damping*Time.time);
GUI.Button(new Rect(pos.x, pos.y, 100, 50), "Demo Button");
}
Let us know the outcome.
Your answer
Follow this Question
Related Questions
pixelInset to Move a GUITexture C# 0 Answers
How to make a GUITexture fade In? 1 Answer
Moving gui texture 1 Answer
How to draw gui without border? 1 Answer
texture type GUI vs texture 1 Answer