Hi all,
it’s a noob question here, but I need to create a sprite wich grow scale when it appears.
For now, when the bullet hit a wall, a new gameobject is creating at the impact point, the new gameobject is stocked into the variable “newGameObject”, and the scale of the newGameObject.transform is lerped 0 to 1. But the problem here, is when an other bullet hit the wall, then the first sprite stop growing, and the second start growing.
The problem here is that I don’t know how to do all sprite transform scale growing at the same time.
Maybe I need the store them in a gameobject list ? Can anyone give me a code example for this ? thanks a lot
Sorry: no code, but here is what I would suggest:
This sounds like the perfect situation to create a MonoBehavior class. This is a class, which like spriterenderer, you can “attach” to a game object (a “component”).
These classes have an “Update” function which is executed every cycle.(when attached to an active object) … (Unity - Scripting API: MonoBehaviour.Update())
They also have the ability to detect collisions, e.g (Unity - Scripting API: MonoBehaviour.OnCollisionEnter(Collision))
Lasty, each instance of a monobehavior, can store its own variables- like say… a “wallHit” boolean, and a “hitTime” float.
Using these in conjuction, you can have EACH bullet determine when it has hit the wall, and alter it’s own scale appropriately. They can even destroy themselves after a while. (you can compare your “hitTime” value with Time.time (Unity - Scripting API: Time.time)
To put your new monobehavior derived class onto a bullet object, by either adding it to the bullet prefab, or use AddComponent to do it at runtime. (Unity - Scripting API: GameObject.AddComponent)