예제 #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
    void SpawnNpc()
    {
        if (enemy && spawn_timer < 1)
        {
            return;
        }
        spawn_timer = 0;
        float d = 1000;
        float x2 = 0, z2 = 0;
        int   index = 0;

        //Debug.Log("Called "+enemy);
        if (enemy)
        {
            //Debug.Log("Players size" + players.Count);
            float x = players[0].transform.position.x;
            float z = players[0].transform.position.z;

            for (int i = 1; i < players.Count; i++)
            {
                float x1 = players[i].transform.position.x;
                float z1 = players[i].transform.position.z;
                float d1 = (x - x1) * (x - x1) + (z - z1) * (z - z1);
                if (d1 < d)
                {
                    d     = d1;
                    x2    = x1;
                    z2    = z1;
                    index = i;
                }
            }
        }
        //Debug.Log("Minimum distance " + d + " at i " + index);
        Vector3 temp = new Vector3(Random.Range(2, 198), 1, Random.Range(2, 198));

        if (enemy && d < 200)
        {
            temp = new Vector3(x2, 1, z2);
        }

        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);
            npcWalker.Add(go.gameObject);
        }
        //else
        //{
        //    SpawnNpc();
        //}
    }
예제 #3
0
    void SpawnNpc()
    {
        Vector3 temp = new Vector3(Random.Range(2, 198), 1, Random.Range(2, 198));

        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);
            npcWalker.Add(go.gameObject);
        }
        else
        {
            SpawnNpc();
        }
    }
예제 #4
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);
            }
        }
    }