Esempio n. 1
0
    private void ProduceUnits()
    {
        if (queuedUnits == 0)
        {
            return;
        }

        unitTimer += Time.deltaTime;

        if (unitTimer < unitSpawnTime)
        {
            return;
        }

        GameObject unitInstance = Instantiate
                                      (unitPrefab.gameObject, unitSpawnPoint.position, unitSpawnPoint.rotation);

        NetworkServer.Spawn(unitInstance, connectionToClient);

        Vector3 spawnOffset = UnityEngine.Random.insideUnitSphere * spawnMoveRange;

        spawnOffset.y = unitSpawnPoint.position.y;
        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset);

        queuedUnits--;
        unitTimer = 0;
    }
Esempio n. 2
0
    private void ProduceUnits()
    {
        if (queuedUnits == 0)
        {
            return;
        }

        unitTimer += Time.deltaTime;

        if (unitTimer < unitSpawnDuration)
        {
            return;
        }

        GameObject unitInstance = Instantiate(
            unitPrefab.gameObject,
            transform.position + (gatherPoint.position - transform.position).normalized * 2.0f,
            gatherPoint.rotation);

        NetworkServer.Spawn(unitInstance, connectionToClient);

        Vector3 spawnOffset = Random.insideUnitSphere * spawnMoveRange;

        spawnOffset.y = gatherPoint.position.y;

        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(gatherPoint.position + spawnOffset);

        queuedUnits--;
        unitTimer = 0.0f;
    }
Esempio n. 3
0
    private void ProduceUnits()
    {
        //If no units queued return
        if (queuedUnits == 0)
        {
            return;
        }

        //Increase time
        unitTimer += Time.deltaTime;
        if (unitTimer < unitSpawnDuration)
        {
            return;
        }

        //Spawn unit on client & then server
        GameObject unitInstance =
            Instantiate(unitPrefab.gameObject, unitSpawnPoint.position, unitSpawnPoint.rotation);

        NetworkServer.Spawn(unitInstance, connectionToClient);

        //Spawn on offset of spawnpoint, but keey same y point
        Vector3 spawnOffset = Random.insideUnitSphere * spawnMoveRange;

        spawnOffset.y = unitSpawnPoint.position.y;

        //Server move unit to new vector3 position with offset
        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset);

        queuedUnits--;
        unitTimer = 0;
    }
Esempio n. 4
0
    private void ProduceUnits()
    {
        if (queuedUnits == 0)
        {
            return;
        }

        //Increase Timer
        unitTimer += Time.deltaTime;

        if (unitTimer < unitSpawnDuration)
        {
            return;
        }

        //Spawnin Prefab on the Server
        GameObject unitInstantiate = Instantiate(unitPrefab.gameObject, unitSpawnPoint.position, Quaternion.identity);

        //Spawning prefab on the Network So Clients Can Get This Instantiation
        NetworkServer.Spawn(unitInstantiate, connectionToClient); //ConnectionToClient = Spawning object Belongs to the client itself ("This prefab Belongs to me").
        //"NetworkServer.Spawn(unitInstantiate);" = //If there is no comma as it is, Instantiated Object belongs to the Server

        //Moving Units Nearby, To Not Stacking Top Of Eachother
        Vector3 spawnOffset = Random.insideUnitSphere * spawnMoveRange;

        spawnOffset.y = unitSpawnPoint.position.y;

        UnitMovement unitMovement = unitInstantiate.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset);

        //Reset Timer
        queuedUnits--;
        unitTimer = 0f;
    }
    private void ProduceUnits()
    {
        if (queuedUnits == 0)
        {
            return;
        }                            // if no queued units, exit method

        unitTimer += Time.deltaTime; // add frame time onto unit timer

        if (unitTimer < unitSpawnDuration)
        {
            return;
        }                                      // exit method until unitTimer equal to or greater than unitSpawnDuration

        GameObject unitInstance = Instantiate( // spawn prefab on the server
            unitPrefab.gameObject,
            unitSpawnPoint.position,
            unitSpawnPoint.rotation);

        NetworkServer.Spawn(unitInstance.gameObject, connectionToClient); // spawn unit on the network so clients receive, and make the client who owns the spawner the owner.

        Vector3 spawnOffset = Random.insideUnitSphere * spawnMoveRange;   // set up random spawn offset so units don't stack onto each other

        spawnOffset.y = unitSpawnPoint.position.y;

        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset); // move unit to the spawn point position + a random offset

        queuedUnits--;                                                  // unit produced so decrement queuedUnits
        unitTimer = 0f;                                                 // reset unit timer
    }
Esempio n. 6
0
    private void ServerProduceAUnit()
    {
        GameObject unitInstance = Instantiate(unitPrefab.gameObject, unitSpawnPoint.position, unitSpawnPoint.rotation);

        NetworkServer.Spawn(unitInstance, connectionToClient);

        // random vector in a sphere
        Vector3 spawnOffset = UnityEngine.Random.insideUnitSphere * spawnMoveRange;

        // don't want to move up/down... keep that as it was
        spawnOffset.y = unitSpawnPoint.position.y;

        // move our unit a touch (so they don't all stack up)
        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset);
    }
Esempio n. 7
0
    //[Command]
    void CmdSpawnUnit()
    {
        GameObject unitInstance = Instantiate(unitPrefab.gameObject, spawnPoint.position, spawnPoint.rotation);

        NetworkServer.Spawn(unitInstance, connectionToClient);

        //Vector3 spawnOffset = spawnMoveRange * UnityEngine.Random.onUnitSphere;
        //spawnOffset.y = unitInstance.transform.position.y;
        Vector3 spawnOffset = spawnPoint.transform.forward * UnityEngine.Random.Range(2f, 4f);

        spawnOffset.x = UnityEngine.Random.Range(-3f, 3f);
        Debug.Log("spawn offset: " + spawnOffset);

        UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>();

        unitMovement.ServerMove(unitInstance.transform.position + spawnOffset);

        //TargetSelectNewlySpawnedUnit(connectionToClient, unitInstance);
    }