I have been watching an endless runner tutorial on YouTube lately, but I am stumped on the part where the platforms are supposed to duplicate and move a little bit to the right so that the player can run endlessly. I however didn’t do my platforms the same way as the guy in the video did his, I made mine in paint.net as one big platform that i wanted to use. He made his from 2d squares basically. I didn’t want to do it exactly like he did but every time i use the instantiate code it either duplicates in the exact position. When I did try it his way it would duplicate them correctly and it would move right on the x axis as intended, however the platforms would be tilted 90 degrees when they should be flat. If anyone could help me with this problem i’m having I would gladly appreciate it.
This is how my platforms look and what it does with the script I have for it.
This is the code I wrote for the platforms.
using UnityEngine;
using System.Collections;
public class PlatformGenerator : MonoBehaviour {
public GameObject thePlatform;
public Transform generationPoint;
public float distanceBetween;
private float platformWidth;
// Use this for initialization
void Start () {
platformWidth = thePlatform.GetComponent<BoxCollider2D> ().size.x;
}
// Update is called once per frame
void Update () {
if (transform.position.x < generationPoint.position.x)
{
transform.position = new Vector3(transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
Instantiate (thePlatform, transform.position, transform.rotation);
}
}
}