- Home /
Endless Runner, instantiate map
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)";
}
}
Any type of help would be appreciated!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
need help with a script 1 Answer
How to make the player move a fixed distance? (Tile per tile) 0 Answers
Hello Im making a Game for mobile and want two floating joysticks one on either side of the screen. 0 Answers
Unable to find problems with 2d-scrolling movement code. 2 Answers