- Home /
only player can activate triggers?
alright, so here's some code:
void OnTriggerEnter2D (Collider2D col)
{
switch (col.gameObject.name)
{
case "enable":
GameCon4.disabledddd = false;
break;
case "disableeee":
GameCon4.disabledddd = true;
Enabler4.IsUsableeee = true;
break;
if the player enters the "disableeee" gameObject, the object does something. but it does'nt need to be the player, anything that just is inside the collider can enter the trigger. how do i modify the code so that only the player can be the trigger?
Comment
Answer by NoahDaNerd · Oct 19, 2020 at 11:55 AM
You should put your code on the trigger objects, not the player.
Make the player's tag "Player" 
Put this code on the disableeee object:
void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
GameCon4.disabledddd = true;
Enabler4.IsUsableeee = true;
}
}
And this code on the enable object:
void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
GameCon4.disabledddd = false;
}
}
Your answer