Fix? The object of type 'GameObject' has been destroyed but you are still trying to access it. Your

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);
}
}
}

What’s assigned to your “thePlatform” variable? If you’ve used the actual platform object in the scene, then destroy that object, then it has nothing to make a clone of. Make the platform a prefab, and link up that prefab to that variable instead.

1 Like

Thank you so much! Fixed!