0

I created a gameobject with a collider box so that I can tell when the player enters a specific area of the map.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BearArea : MonoBehaviour
{
    public GameObject bear;
    private OrsoAI bearScript;
    
    void Start()
    {
        bearScript = bear.GetComponent<OrsoAI>(); 
    }

    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            print("player nell'area");
            bearScript.onBearArea = true; 
        }
    }

    public void OnTriggerExit(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            print("player fuori dall'area");
            bearScript.onBearArea = false; 
        }
    }
}

But the system when the player enters the area keeps looping both prints. Could it be that as he walks into the area the triggher can't detect everything well? Or is there something wrong with the code?

I saw that when he leaves the area the last message printed is "player out of the area" so in the background it is correct except for the loop when the player is in the area.

0 Answers0