Пример #1
0
    void Update()
    {
        if (NPCStateCurrent == NPCState.Alerted)
        {
            NPCStateCurrent = NPCState.Evacuating;
            SetColor(Color.red);
            NPCMoveToEscape();
        }

        civilianList = civManager.UpdateCivilianList();
        if (NPCStateCurrent == NPCState.Exploring)
        {
            if (playerController.GetPlayerDangerous())
            {
                if ((player.transform.position - this.transform.position).magnitude < detectionRange)
                {
                    Debug.Log("Player within range");
                    if (Vector3.Angle(this.transform.forward, player.transform.position - this.transform.position) <= (120 / 2)) // AI can see player
                    {
                        Debug.Log("Player within FOV");
                        RaycastHit hit;
                        if (Physics.Linecast(this.transform.position, player.transform.position, out hit))
                        {
                            Debug.Log("Pass");
                            Debug.Log(hit.transform.tag);
                            if (hit.transform.tag == "Player")
                            {
                                NPCStateCurrent = NPCState.Alerted;
                            }
                        }
                    }
                }
            }
            CheckOtherCivs();
        }



        if (playerController.GetAlertAll())
        {
            NPCStateCurrent = NPCState.Alerted;
        }



        timer += Time.deltaTime;
        if (NPCStateCurrent == NPCState.Exploring)
        {
            if (timer >= wanderTimer)
            {
                Vector3 newPos = RandomNavSphere(originalPosition.position, wanderRadius, -1);
                agent.SetDestination(newPos);
                timer = 0;
            }
        }
    }
Пример #2
0
    void Start()
    {
        Debug.Log("Start");
        originalPosition = this.transform;
        NPCStateCurrent  = NPCState.Exploring;

        civManager = civilianContainer.GetComponent <CivilianManager>();

        civilianList = new List <GameObject>();  //Add all civilians to list
        civilianList = civManager.UpdateCivilianList();
    }