Hi Everyone,
Over the last couple of months I’ve been trying to wrap my head around some programming in Unity but I am NOT a programmer, so I’ve been running into a lot of roadblocks.
I’ve been working with a script to animate textures that I grabbed from the Unity Wiki:
var uvAnimationTileX = 4;
//Here you can place the number of columns of your sheet.
var uvAnimationTileY = 1;
//Here you can place the number of rows of your sheet.
var framesPerSecond = 1.0;
function Update () {
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
I’m using this texture on gameObject that is instantiated by another. The texture shows a sequence of numbers counting down. The problem I’m having is that the countdown seems to be based on a global time, rather than the amount of time the object has been around for. I could have a hundred of these objects on screen, all generated at different times, but they will all show the same frame of the texture. Is there a way to have the time based off when the object was instantiated, rather than when the program was first run?
I’ve gone through the forum as well as the script reference and I can’t find anything that describes what I’m looking for.
Any help would be greatly appreciated!
Thanks.