Why it can’t destroy clones?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Obstacle : MonoBehaviour
{
private float leftBound = -15;
private PlayerController playerControllerScript;
public GameObject obstaclePrefab;
private Vector3 spawnPos = new Vector3(-3, 2, -10);
private GameObject prefabPosition;
// Start is called before the first frame update
void Start()
{
playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
}
// Update is called once per frame
void Update()
{
if(transform.position.y < leftBound && gameObject.CompareTag("Obstacle")){
Destroy(gameObject);
prefabPosition = Instantiate(obstaclePrefab, spawnPos, obstaclePrefab.transform.rotation);
}
}
}
Did you drag n drop the obstacle Asset in the obstaclePrefab variable? Could you explain a bit more what is happening please?
– Cyber_CatsYes, obstacle Asset is in the variable. So I made script so when obstacle left bounds (y = -15) obstacle should be destroyed, then make another one obstacle. But what is happening is that it destroys the original obstacle, spawns a clone, but when clone left the bounds, it wont be destroyed, and because of that another clone wont spawn.
– TITUXS