- Home /
How To Re-use model Like Subway Surfer & Temple Run Game?
Hello Good Morning Everyone, I am working on 1 infinite run game then i need to reuse my model, I am confused how should i re-use my model again and again, like Subway Surfer and Temple Run Which technique should i use for path creation or reuse model ??
Please give me your suggestions or advice
Here is one link on object pooling:
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
Answer by Drshk7 · Dec 24, 2013 at 04:54 AM
You could make something like it destroys it and instantiates it when you restart. Or, you can change the objects position to the starting point.
BTW: If this answer is not what you wanted, I suggest you should reword your question. What do you mean reuse? Like when you die you play again and the player model is there?
No actually like Subway Surfer we cant use infinite model then our model have some limit then this model i need to use in same time again and again....Suppose my model Z start position is 0 and End Position is 10 now i want to use it up to z End Position 1000 then any good idea to do that??
Answer by abduomar · May 01, 2016 at 05:31 AM
I think this should help you ;) https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling
Answer by DevCas1 · May 13, 2016 at 04:51 PM
The object pooling thing could help. However, if you do not know where the first end ends, and the next end needs to begin, you need to find something for that. I tried to make an infinite runner myself, and I added an A and B point to every piece the player has to "run" over.
This way, you make it so that the B point of the next piece overlaps with the A point of the last piece. If used, the objects will ALWAYS fit together like a glove.
Adding the child A and B shouldn't be hard, as local positions are quickly done, and ALWAYS the same.
Code I used:
public void Place()
{
GameObject lastUsedIndex = halfpipes[Random.Range(0, 5)];
GameObject spawnedBlock = (GameObject)Instantiate(lastUsedIndex, spawnPos, Quaternion.identity);
float nextZ = spawnedBlock.gameObject.GetComponentInChildren<Transform>().Find("A").transform.position.z;
float lastZ = lastUsedIndex.GetComponentInChildren<Transform>().Find("B").transform.position.z;
spawnPos.z = nextZ - lastZ;
}
Hope it helps
Your answer
![](https://koobas.hobune.stream/wayback/20220613124759im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Walk/run animation moves main camera up and down (first person) 1 Answer
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
How can I collect the positions of my waypoint objects which mark out a path or route? 2 Answers