It wont let me destoy my cloned cube. After it clones and respawns (Im using an Instantiated prefab) and the player walks on it it doesn’t get destroyed and gives tons of points if you stay on it. I made it to where the cloned version has the same name as the original but it still wont work, its suppose to destroy once the player walks on it. and again the point system still works the cloned object just won’t destroy. How do i fix this? Heres my code for it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollisionPlayerOne : MonoBehaviour
{
public GameObject ObjPrefab;
public pOneMovement PlayerOne;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "playerOneGoal")
{
ScoreScript.scoreValue += 1;
Destroy (col.gameObject);
spawnPrefab();
}
}
private void spawnPrefab()
{
ObjPrefab = Instantiate(ObjPrefab) as GameObject;
ObjPrefab.transform.position = new Vector3(-3.63f, 0.6f, 1.24f);
ObjPrefab.name = "playerOneGoal";
}
}