- Home /
Question by
Funnuraba · Sep 02, 2017 at 04:32 AM ·
instantiatetriggercomparetagtrim
Respawn a obect after entering a trigger only if the object is tagged
I'm trying to respawn a object when entering a trigger field only if the object is tagged as "Player".
Here is the code: public class SpawnCollectibles : MonoBehaviour {
public GameObject Gas;
public Transform spawnpoint;
void OnTriggerEnter(Collider col)
{
if (col.CompareTag ("Player"))
{
Spawn();
}
}
void Spawn()
{
Instantiate(Gas, spawnpoint.position, spawnpoint.rotation);
}
}
This code doesn't seem to work & i'm kinda stuck.
Comment
Your answer
Follow this Question
Related Questions
Show GUI Texture on Trigger and Instantiate Object if Button pressed while In Trigger? 1 Answer
Checking if object intersects? 1 Answer
Instansiate object into hand with a trigger, help... 0 Answers
How can I make the Player be destroyed when I touch the end of the camera? 1 Answer
Help with trigger 1 Answer