When i play the game, my first platform is destroyed, the second its still here and no generate another platforms.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformGenerator : MonoBehaviour
{
public GameObject thePlatform;
public Transform generationPoint;
public float distanceBetween;
private float platformWidth;
// Start is called before the first frame update
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);
}
}
}
and for destroy the platforms
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformDestroyer : MonoBehaviour
{
public GameObject platformDestructionPoint;
// Start is called before the first frame update
void Start()
{
platformDestructionPoint = GameObject.Find ("PlatformDestructionPoint");
}
// Update is called once per frame
void Update()
{
if(transform.position.x < platformDestructionPoint.transform.position.x);
{
Destroy (gameObject);
}
}
}