I am having trouble with the Instantiate command. I have a script that is supposed to replace the object what it is a part of with anther, and it works! put for a little bit because it is creating clones and then clones of clones and so on and so forth until it no longer can place them
and this is probably the culprit
I don’t know why this is happening
put here is the code
using Unity.Mathematics;
using UnityEngine;
public class Lever_slfedistract : MonoBehaviour
{
public GameObject ON;
public GameObject OFF;
private Vector3 vector3;
private quaternion quaternion;
private void Awake()
{
vector3 = transform.position;
quaternion = transform.rotation;
}
public void Lever_ON()
{
Instantiate(OFF,vector3,quaternion);
gameObject.SetActive(false);
}
public void Lever_OFF()
{
Instantiate(ON, vector3, quaternion);
gameObject.SetActive(false);
}
}
what I am trying to do is to make it flip back and forth between the two prefabs every time the player click on them and the click detection is done but I am have trouble with the flipping. ty