예제 #1
0
    public void SpawnFollowers(GameObject _player)
    {
        int max = 10;

        for (int i = 0; i < max; i++)
        {
            Vector3 temp = _player.transform.position + Random.insideUnitSphere * Random.Range(3, 10);

            NavMeshHit hit;
            if (NavMesh.SamplePosition(temp, out hit, 50.0f, NavMesh.AllAreas))
            {
                Vector3 pos = hit.position;

                NpcAgent go = Instantiate(npcPrefab, pos, Quaternion.identity, npcRoot.transform);
                go.currentState = NpcAgent.State.Following;
                go.AddPlayer(_player);
            }
            else
            {
                max++;
                continue;
            }
        }
        _player.GetComponent <Agent>().amount += 10;
    }
예제 #2
0
    public void AddNpc(GameObject npc)
    {
        NpcAgent npcController = npc.GetComponent <NpcAgent>();

        if (npcController.currentState == NpcAgent.State.Wondering)
        {
            npcController.AddPlayer(gameObject);
            npcController.offset = npcController.offset * Mathf.RoundToInt(amount / 5);
            AddAmount(1);
        }
        else if (npcController.currentState == NpcAgent.State.Following && npcController.player != gameObject)
        {
            if (npcController.player.GetComponent <Agent>().amount < amount)
            {
                npcController.player.GetComponent <Agent>().AddAmount(-1);
                npcController.AddPlayer(gameObject);
                npcController.offset = npcController.offset * Mathf.RoundToInt(amount / 5);
                AddAmount(1);
            }
        }
    }