This post has been wikified, any user with enough reputation can edit it.
Question by
arthymon · Dec 18, 2016 at 05:04 AM ·
scripting probleminstantiatemoving
Endless Runner map instantiate
Hi guys, i am pretty new to Unity , and i have a question to ask . So basically i'm making a simple endless runner (only map and obstacles move) , and map itself is a prefab , so i created trigger on a prefab, and when player hits it a new prefab map instantiates . Also i have a button "gas pedal", when you press it map starts move faster . It would be easy to locate position of where to instantiate next , if it weren't for speed, because it constantly changes. Here is my code for map instantiation:
Void OnTriggerEnter(Collider other)
{
if (moving.GetComponent<MoveMap>().speed != 0 )
{
if (other.tag == "Player")
Instantiated = Instantiate(swapped, new Vector3(distance, 0, 0), Quaternion.identity) as GameObject;
if (Instantiated != null)
{
distance = Instantiated.transform.position.x ;
if (Instantiated.GetComponent<TimerMap>() == null)
Instantiated.AddComponent<TimerMap>();
Instantiated.name = "BasicMap(Clone)";
}
}
Comment