public void Respawn(ScavangerManager scavanger)
    {
        GameObject[] scavangers             = GameObject.FindGameObjectsWithTag(scavanger.gameObject.tag);
        Vector3?     enemyScavangerPosition = null;

        foreach (var i_scavanger in scavangers)
        {
            if (i_scavanger != scavanger.gameObject)
            {
                enemyScavangerPosition = i_scavanger.transform.position;
                break;
            }
        }

        Transform furthestSpawnPoint = respawnPoints[0];
        float     longestDistance    = 0;
        Vector3   scalar             = new Vector3(1, 0, 1);

        foreach (var spawnPoint in respawnPoints)
        {
            Vector3 v = spawnPoint.position - (Vector3)enemyScavangerPosition;
            v.Scale(scalar);
            float distance = v.magnitude;

            if (distance > longestDistance)
            {
                furthestSpawnPoint = spawnPoint;
                longestDistance    = distance;
            }
        }

        scavanger.transform.position = furthestSpawnPoint.position;
        scavanger.OnRespawn();
    }
Exemple #2
0
    public void OnTriggerEnter(Collider other)
    {
        ScavangerManager scavanger = other.GetComponent <ScavangerManager>();

        if (scavanger != null && scavanger != owner)
        {
            Grabber grabber = scavanger.GetComponent <Grabber>();

            if (grabber.GetGrabbedObject() == tools)
            {
                if (numberOfEnergyCells > 0)
                {
                    Grabable energyCell = Instantiate(energyCellPrefab).GetComponent <Grabable>();
                    NetworkServer.Spawn(energyCell.gameObject);

                    if (EnergyCellStolenEvent != null)
                    {
                        EnergyCellStolenEvent(energyCell);
                    }

                    grabber.Swap(energyCell);
                    numberOfEnergyCells--;
                }
                else
                {
                    grabber.Swap(null);
                }
            }
        }
        else if (scavanger != null)
        {
            Grabber  grabber = scavanger.GetComponent <Grabber>();
            Grabable grabbed = grabber.GetGrabbedObject();
            if (grabbed != null && grabbed.tag == "EnergyCell")
            {
                numberOfEnergyCells++;

                if (EnergyCellPlacedEvent != null)
                {
                    EnergyCellPlacedEvent();
                }

                grabber.Swap(null);
                Destroy(grabbed.gameObject);
            }
        }
    }
Exemple #3
0
 public void CmdAssignPlayerTwo(GameObject player)
 {
     Debug.Log("isServer player two 2: " + isServer);
     playerTwo       = player.GetComponent <ScavangerManager>();
     rocketTwo.owner = playerTwo;
 }
Exemple #4
0
 public void CmdAssignPlayerOne(GameObject player)
 {
     Debug.Log("isServer player one 2: " + isServer);
     playerOne       = player.GetComponent <ScavangerManager>();
     rocketOne.owner = playerOne;
 }
Exemple #5
0
 public static void AssignPlayerTwo(GameObject player)
 {
     playerTwo = player.GetComponent <ScavangerManager>();
     //rocketTwo.owner = playerTwo;
 }
Exemple #6
0
 public static void AssignPlayerOne(GameObject player)
 {
     playerOne = player.GetComponent <ScavangerManager>();
     //rocketOne.owner = playerOne;
 }