- Home /
Monster starts attack when player enter to sphere collider
Hello guys I want to create a monster attack script I already created a monster movement but now I need to create something like that:
If player enter to sphere collider enemy starts hitting with delay 1 sec.
Or should I do it with another way ?
(I wanted to use Raycast but I dont know its a good idea)
Can you guys help me with that ?
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log ("He entered");
playerInSphere = true;
}
}
void Update ()
{
if (playerInSphere == true)
{
//hit player
}
}
It looks like your script already does what you want. Is it not detecting the player?
You could disable the collider after player is detected. That might help with performance, as there'd be one collider less to listen to. You could also assign the specific player as "target", especially if you have multiple players.
What is it exactly that you need help with?
Answer by AshwinTheGammer · Oct 03, 2017 at 12:30 PM
What do you want to do it seems that your script already does what you want. Clarify more your answer.