Пример #1
0
        IEnumerator EnemiesCoroutine()
        {
            const float MIN_TIME = 5.0f;
            const float MAX_TIME = 10.0f;

            yield return(new WaitForSeconds(Random.Range(MIN_TIME, MAX_TIME)));

            for (int i = 0; i < Robots.Count; i++)
            {
                Vector3 position = GetPossibleEnemySpawnPosition();

                GameObject go = Instantiate(enemyPrefabs[enemyPrefabs.Length - 1], position,
                                            Quaternion.Euler(Random.value * 360.0f, Random.value * 360.0f,
                                                             Random.value * 360.0f)) as GameObject;

                NetworkEnemy       enemy   = go.GetComponent <NetworkEnemy>();
                NetworkPlayerRobot closest = GetClosestPlayer(position);
                enemy.target = closest.transform;

                NavMeshAgent agent = go.GetComponent <NavMeshAgent>();
                agent.speed        = Random.Range(1.5f, 2.0f);
                agent.acceleration = agent.speed * 4.0f;

                NetworkServer.Spawn(go);
            }
        }
Пример #2
0
        void RpcFindNewTarget()
        {
            NetworkPlayerRobot potentialTarget = NetworkRobotGameManager.Instance.GetClosestPlayer(transform.position);

            if (potentialTarget != null)
            {
                target = potentialTarget.transform;
            }
        }
Пример #3
0
        public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer,
                                                               GameObject gamePlayer)
        {
            LobbyPlayer        lobby = lobbyPlayer.GetComponent <LobbyPlayer>();
            NetworkPlayerRobot robot = gamePlayer.GetComponent <NetworkPlayerRobot>();

            robot.name       = lobby.name;
            robot.playerName = lobby.playerName;
            robot.color      = lobby.playerColor;
            robot.score      = 0;
            robot.lifeCount  = 3;
        }
Пример #4
0
 void OnCollisionEnter(Collision coll)
 {
     if (coll.gameObject.tag == "Player")
     {
         //we collided with a player, check if they are powered up.
         NetworkPlayerRobot otherRobot = coll.gameObject.GetComponent <NetworkPlayerRobot>();
         if (otherRobot.poweredUp && !poweredUp)
         {
             Killed();
         }
         else
         {
             BounceBack(otherRobot.gameObject.transform);
         }
     }
 }
Пример #5
0
        public NetworkPlayerRobot GetClosestPlayer(Vector3 from)
        {
            NetworkPlayerRobot result = null;
            float closestDist         = float.MaxValue;

            foreach (NetworkPlayerRobot npr in Robots)
            {
                float playerDist = Vector3.Distance(from, npr.transform.position);
                if (playerDist < closestDist)
                {
                    closestDist = playerDist;
                    result      = npr;
                }
            }

            return(result);
        }
Пример #6
0
        void Update()
        {
            if (Robots.Count > 1) //our game start check (more than one player has started)
            {
                running = true;
            }

            if (!running) //only check for game end after it has started
            {
                return;
            }

            int numLivePlayers = 0;
            NetworkPlayerRobot oneLivePlayer = null;

            for (int i = 0; i < Robots.Count; ++i)
            {
                if (Robots[i].lifeCount > 0)
                {
                    numLivePlayers++;
                    oneLivePlayer = Robots[i];
                }
            }

            if (numLivePlayers == 1)
            {
                RpcDisplayWinner(oneLivePlayer.playerName);

                StartCoroutine(ReturnToLobby());
                return;
            }

            if (!spawningCollectibles && numActiveCollectibles == 0)
            {
                spawningCollectibles = true;
                StartCoroutine(CollectiblesCoroutine());
            }

            if (!spawningPowerPills && numActivePowerPills == 0)
            {
                spawningPowerPills = true;
                StartCoroutine(PowerPillCoroutine());
            }
        }
Пример #7
0
 void OnTriggerEnter(Collider collider)
 {
     if (collider.gameObject.tag == "Player")
     {
         //we collided with a player, check if they are powered up.
         NetworkPlayerRobot robot = collider.gameObject.GetComponent <NetworkPlayerRobot>();
         if (robot.poweredUp)
         {
             Killed();
             robot.score += scoreValue;
         }
         else
         {
             if (state == EnemyState.Hunting)
             {
                 robot.Killed();
                 //find next target
                 RpcFindNewTarget();
             }
         }
     }
 }
Пример #8
0
        void OnTriggerEnter(Collider collider)
        {
            if (isDestroyed)
            {
                return;
            }

            //we collide so we dirty the NetworkTrasnform to sync it on clients.
            netTransform.SetDirtyBit(1);

            if (collider.gameObject.tag == "Player")
            {
                //we collided with the player, they have collected me .
                NetworkPlayerRobot robot = collider.gameObject.GetComponent <NetworkPlayerRobot>();
                robot.score += scoreValue;
                if (isPowerUp)
                {
                    robot.ServerPowerUp(true);
                }

                collectibleCollider.enabled = false;
                Collected();
            }
        }