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:
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!
asked Jun 10 '11 at 12:03 AM
You could handle this in multiple ways. Using what you have you could use a boolean that tracks the game state and an offset for the time it actually starts working - for example (remember to add your other variables and code from your first script):
A tidier way to do it would be to have a co-routine running every second which counted just shifted the texture offset incrementally. In this pesudo example you kick of the co-routine by sending the startCountDown message to your countdown object.
EDIT If you are instancing these objects and want them to count from when they are created do this: