コード例 #1
0
    public void Investigate(Vector3 position)
    {
        foreach (GameObject policeman in policemen)
        {
            if (Vector3.Distance(policeman.transform.position, position) <= suspicion)
            {
                PolicemanBehavior policemanBehavior = policeman.GetComponent <PolicemanBehavior>();
                if (policemanBehavior.attitude == PolicemanBehavior.attitudes.Idling)
                {
                    policemanBehavior.StartInvestigation(position);
                }
                else
                {
                    GameObject player            = GameObject.FindGameObjectWithTag("Player");
                    Vector2    policemanPosition = new Vector2(policeman.transform.position.x, policeman.transform.position.z);
                    Vector2    playerPosition    = new Vector2(player.transform.position.x, player.transform.position.z);
                    Vector2    direction         = (playerPosition - policemanPosition).normalized;
                    bool       visible           = Vector2.Angle(new Vector2(policeman.transform.forward.x, policeman.transform.forward.z), direction) < policemanBehavior.FOV / 2;

                    // A raycast should be done aswell, ignoring people
                    // Also a max vision radius should be implemented
                    if (visible)
                    {
                        policemanBehavior.StartAttacking();
                    }
                }
            }
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        gameController = Camera.main.GetComponent <GameController>();
        agent          = gameObject.GetComponent <NavMeshAgent>();

        // Applying personality parameters
        agent.speed = Random.Range(personality.minSpeed, personality.maxSpeed);

        // Generate mind sequence
        if (mode == modes.Policeman)
        {
            policemanDebugRangeInstance = Instantiate(policemanDebugRangePrefab, transform.position, transform.rotation, transform);
            policemanBehavior           = gameObject.AddComponent <PolicemanBehavior>();
        }
        else
        {
            mindLength   = (int)Mathf.Min(gameController.maxMindLength, mindLength);
            mindSequence = gameController.RegisterBystander();

            if (mindSequence.Length <= 0)
            {
                Destroy(gameObject);
                return;
            }
            else
            {
                // By default, player doesn't know the mind sequence of said bystander
                foreach (char _ in mindSequence)
                {
                    mindSequenceMask.Add(false);
                }
            }
            if (mode == modes.Wandering)
            {
                wanderClock = Random.value * wanderMaxEvery;
            }
        }
    }