Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (isServer)
        {
            if (targetPlayer != null)
            {
                Vector3 player = targetPlayer.transform.position;
                agent.SetDestination(player);

                if (Vector3.Distance(player, transform.position) <= (agent.stoppingDistance + 0.1f))
                {
                    // Attack
                    Attack();
                    FaceTarget();
                }
            }
            else
            {
                if (!isPatrolling)
                {
                    isPatrolling = true;
                    StartCoroutine(Patrol());
                }

                // Check if any players are within lookRadius
                Collider[] hitColliders = Physics.OverlapSphere(transform.position, lookRadius, layerMask);
                foreach (Collider collider in hitColliders)
                {
                    // If royale, only target human players
                    if (GameManager.instance.isRoyale)
                    {
                        if (RoyaleManager.GetStatus(collider.name) != Player.PlayerStatus.Alive)
                        {
                            continue;
                        }
                    }

                    // Set player as new pathing target
                    targetPlayer = collider.gameObject;
                    isPatrolling = false;
                    targetPlayer.GetComponent <Player>().playerDied += ResetPlayer;
                    break;
                }
            }
            currVelocity = agent.velocity.magnitude;
        }
        else
        {
            // Animate movement on client
            animator.SetFloat("Speed_f", currVelocity);
        }
    }
Ejemplo n.º 2
0
    void PlayersToSpawnEnemy()
    {
        players = GameManager.GetAllPlayers();

        System.Guid randomId = enemyIds[Random.Range(0, enemies.Length)];
        if (GameManager.instance.isRoyale)
        {
            foreach (GameObject player in players)
            {
                if (RoyaleManager.GetStatus(player.name) == Player.PlayerStatus.Alive)
                {
                    SpawnEnemy(player, randomId);
                }
            }
        }
        else
        {
            foreach (GameObject player in players)
            {
                SpawnEnemy(player, randomId);
            }
        }
    }