Skip to content

How to: Using Sequence.Create(), Instantiating GameObject with delay then animating them, destroying and repeat N number of time #43

Answered by KyryloKuzyk
IAFahim asked this question in FAQ
Discussion options

You must be logged in to vote

To create a Sequence, you should first create all objects the Sequence will animate. So I'm afraid the concept of creating objects on the fly and then animating them doesn't work well with sequences. In addition, Object.Instantiate() and Object.Destroy() are heavy operations that may lead to fps drops, so I can't recommend this approach either.

What you can do is to create these objects in advance, then enable/disable them with .SetActive(bool isActive). Also, this approach can now be used with a Sequence because all GameObject references are known in advance. Here is the code:

GameObject[] gos;

public Sequence AnimateGameObjects() {
    if (gos == null) {
        gos = new GameObject[25];

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KyryloKuzyk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
None yet
2 participants