public class CreateSpikeDamage : MonoBehaviour
{
public float destroy = 5.0f;
public GameObject spikeDamage;
public Transform spikeDamagePos;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
spikeDamage.SetActive(true);
Destroy(spikeDamage, destroy);
Instantiate(spikeDamage, transform.position, transform.rotation);
}
}
}
I want to spawn a gameObject every time I walk onto a trigger, when I walk onto it at first it does what I want but when I walk onto it again it spawns the clones but they are not active. What am I doing wrong? Thanks!
First of all tell us what you want to achieve.
What is SpikeDamage (also I suggest naming your MonoBehaviours with Component in name, like SpikeDamageComponent)
I basically just want to spawn a gameObject when the player goes into a collider that Is trigger that kills the player and after some time the gameObject gets destroyed those two things work. The only thing that doesn’t work is when I go onto the collider again it doesn’t work the gameObject doesn’t spawn again.
First of all a dont know why are you even messing around with gameObject.setActive In SapikeDamage.
The second thing i dont undesratnad why are you doing this.