Esempio n. 1
0
    IEnumerator SpawnBird(Vector3 posPlayer)
    {
        Vector3    posSpawn = transform.position + (Vector3)Random.insideUnitCircle / 3f;
        Basic_Bird bird     = Instantiate(prefabBirds[Random.Range(0, prefabBirds.Count)], posSpawn, Quaternion.identity).GetComponent <Basic_Bird>();

        yield return(null);

        bird.FlyAway(posPlayer);
    }
Esempio n. 2
0
    IEnumerator SpawnBird()
    {
        Vector3 posPlayer;
        float   distanceToPlayer;
        float   lowestDistanceToPlayer;

        while (true)
        {
            while (tree == null || tree.IsCut)
            {
                yield return(new WaitForSeconds(1f));
            }
            lowestDistanceToPlayer = 1000f;
            foreach (GameObject player in PlayerManager.GetPlayerManager.listConnectedPlayers[SceneManager.GetActiveScene().buildIndex])
            {
                posPlayer        = PlayerManager.GetPlayerManager.playerController.transform.position;
                distanceToPlayer = Vector3.SqrMagnitude(transform.position - posPlayer);
                if (lowestDistanceToPlayer > distanceToPlayer)
                {
                    lowestDistanceToPlayer = distanceToPlayer;
                }
                if (distanceToPlayer <= distance * distance && Random.Range(0, 1000) == 0)
                {
                    Vector3    posSpawn = transform.position + (Vector3)Random.insideUnitCircle / 3f;
                    Basic_Bird bird     = Instantiate(prefabBirds[Random.Range(0, prefabBirds.Count)], posSpawn, Quaternion.identity).GetComponent <Basic_Bird>();
                    yield return(null);

                    bird.FlyAway(posPlayer);
                    break;
                }
            }
            if (lowestDistanceToPlayer <= distance * distance * 5)
            {
                yield return(new WaitForFixedUpdate());
            }
            else
            {
                yield return(new WaitForSeconds(4f));
            }
        }
    }