コード例 #1
0
    // Get a random room based on our chance rolls and return a random position within it
    private void GetNewTargetPosition()
    {
        if (gameObject == null)
        {
            return;
        }

        CancelIdle();

        BaseRoom room = GetRandomIdleRoom();

        if (room == null)
        {
            Debug.Log("ERROR! GetRandomIdleRoom() null room ref");
            return;
        }

        Vector3 randomPosition = room.GetRandomPoint();

        // Now ensure we get a valid navmesh position nearest to this point
        NavMeshHit hit;

        NavMesh.SamplePosition(randomPosition, out hit, 20f, 1);
        Vector3 finalPosition = hit.position;

        m_NavAgent.SetDestination(finalPosition);
    }
コード例 #2
0
    private void Spawn()
    {
        if (m_BaseRoom == null)
        {
            return;
        }

        if (m_BaseRoom.GetCurrentCapacity() < MaxRoomCapacity)
        {
            Transform newPerson = Instantiate(PrefabPersonToSpawn);
            newPerson.position = m_BaseRoom.GetRandomPoint();
        }

        InvokeNextSpawn();
    }