Beispiel #1
0
    // Create a unit of a type at the left or right flank
    private void CreateUnit(int type, int positionCode)
    {
        TSVector   position;
        GameObject prefab;
        int        attack = 1, hp = 1;
        FP         range = 0f;


        switch (type)
        {
        case 1:         // Melee Unit
            prefab = this.unitPrefab;
            attack = 10;
            hp     = 30;
            range  = 0f;
            break;

        case 2:         // Ranged Unit
            prefab = this.unit2Prefab;
            attack = 5;
            hp     = 20;
            range  = 3f;
            break;

        default:
            Debug.Log("Incorrect type specified by CreateUnit");
            return;
        }
        UnitData stats = new UnitData(hp, attack, range);


        switch (positionCode)
        {
        case 1:         // Left flank
            position = leftSpawn;
            break;

        case 2:         // Right flank
            position = rightSpawn;
            break;

        default:
            Debug.Log("Incorrect positionCode specified by CreateUnit");
            return;
        }

        position.x *= positionFactor;
        position.z *= positionFactor;
        UnitBehavior unitBehavior = TrueSyncManager.SyncedInstantiate(prefab, position, TSQuaternion.identity).GetComponent <UnitBehavior>();

        unitBehavior.owner = owner;
        unitBehavior.SetData(stats);
    }