- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
betoel2009 · Nov 04, 2012 at 04:13 PM ·
buttontriggersprite animationmouse button
Sprite Animation using mouse, like an interactive ebook
Hi curently i try to make an interactive ebook sprite playing..when i clik on the image the sprite will start the animation once and then stop then get back to the first image..i ended up with "Animating Tiled texture" script..i tried to add Mouse button but then the animation wont start cycling..it only start cycle everytime i hit the trigger with the mouse button..frame by frame..How should i fix it?can you give me a example how it should like..i would apreciate any help or advice.thanks
var columns = 24;
var rows = 1;
var fps = 10.0;
var stopped : boolean;
var startTime: float;
function Start() {
startTime = Time.time;
}
function Update () {
if (Input.GetMouseButtonUp (0)){
if (!stopped) {
var index : int = Mathf.Min(columns * rows - 1, (Time.time - startTime) * fps);
stopped = index == columns * rows - 1;
var size = Vector2 (1.0 / columns, 1.0 / rows);
var columnIndex = index % columns;
var rowIndex = index / columns;
var offset = Vector2 (columnIndex * size.x, 1.0 - size.y - rowIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
}
}
Comment