When using this script and attatching it to a box collider(trigger) that is located at the end of a tile(prefab)(floor piece) it is supposed to destroy the tile and generate a new tile so the ball can continue rolling forward. It runs once then I get a missingreferenceexception error. I am following the book exactly. I was wondering if I’m doing something wrong or if the book is outdated. The book is “Unity 2017 mobile game development”
using UnityEngine;
///
/// Handles spawning a new tile and destroying this one
/// upon the player reaching the end
///
public class TileManager : MonoBehaviour
{
[Tooltip("How much time to wait before destroying " +
“the tile after reaching the end”)]
public float destroyTime = .2f;
void OnTriggerEnter(Collider col)
{
// First check if we collided with the player
if (col.gameObject.GetComponent())
{
// If we did, spawn a new tile
GameObject.FindObjectOfType().SpawnNextTile();
// And destroy this entire tile after a short delay
Destroy(transform.parent.gameObject, destroyTime);
}
}
}