Hey all, I'm a bit of a scripting noob, and was hoping I cold get some scripting help, I have a 5 frame animation which I want to link to 2 GUI buttons, Previous and Next. The end results needs to be so you can manually cycle back and forth the animation set with the 2 buttons. But, when you get to the last frame, the Next button does not bring you back to the first frame, it stays on the last and visa versa with the previous button. How do I create this guys? Thanks.! -Hosse
You should put the textures into an array and use an integer variable to select which texture you want from the array. Increment the integer when the Next button is clicked and decrement it when Previous is clicked. You can then use Mathf.Clamp to make sure the integer doesn't go off the ends of the array:- Code (csharp): var textures: Texture2D[]; var index: int; var prevButtonRect: Rect; var nextButtonRect: Rect; var textureRect: Rect; function OnGUI() { if (GUI.Button(prevButtonRect, "Prev")) { index = Mathf.Clamp(index - 1, 0, textures.Length - 1); } if (GUI.Button(nextButtonRect, "Next")) { index = Mathf.Clamp(index + 1, 0, textures.Length - 1); } GUI.DrawTexture(textureRect, textures[index]); }
I should of mentioned, its 3d geometry that is animated. The geometry has a different position in each of the 5 frames. SO the 2 gui buttons will cycle through the 5 different positions. This make any sense? Thanks! -Hosse
do the exact same thing he mentioned except instead of textures you need an array of transforms, and instead of setting the texture you need to position your camera at the transform EDIT: ok that was vague. Code (csharp): var textures: Texture2D[]; var index: int; var prevButtonRect: Rect; var nextButtonRect: Rect; var cameraT : Transform; function OnGUI() { if (GUI.Button(prevButtonRect, "Prev")) { index = Mathf.Clamp(index - 1, 0, textures.Length - 1); } if (GUI.Button(nextButtonRect, "Next")) { index = Mathf.Clamp(index + 1, 0, textures.Length - 1); } cameraT.position = textures[index].position; cameraT.rotation= textures[index].rotation; }
is there no way i can import my model with 5 frames of animation and the buttons cycle through the anim frame by frame? -Hosse