Beispiel #1
0
    private void SendUnit(ObjectOwnerState sourceInfo, Transform selected)
    {
        // Create unit at source stronghold
        GameObject unit             = Instantiate(unitPrefab, source.position, Quaternion.identity);
        GameObject displayMagnitude = Instantiate(unitCountPrefab, source.position, Quaternion.identity);
        Vector3    dMPos            = displayMagnitude.transform.position;


        displayMagnitude.transform.SetParent(unit.transform);
        displayMagnitude.GetComponent <TextMeshPro>().fontSize = 50;
        displayMagnitude.transform.position = new Vector3(dMPos.x, 15, dMPos.z);

        int strongholdMagnitude = sourceInfo.GetMagnitude();
        int unitMagnitude       = strongholdMagnitude / 2;

        // Only send unit if it has a magnitude
        if (unitMagnitude > 0)
        {
            ObjectOwnerState unitInfo = unit.GetComponent <ObjectOwnerState>();

            unitInfo.SetMagnitude(unitMagnitude);
            unitInfo.player = sourceInfo.player;
            unit.GetComponent <UnitState>().SetSource(source.gameObject);
            unit.GetComponent <Movement>().SetTarget(selected);
            sourceInfo.SetMagnitude(strongholdMagnitude - unitMagnitude);
        }
    }
Beispiel #2
0
    public void RegisterStrongholdClick(Transform selected)
    {
        ObjectOwnerState selectedInfo = selected.GetComponent <ObjectOwnerState>();

        // If source is not yet selected, selected stronghold is the source
        if (source == null && selectedInfo.player != null)
        {
            source = selected;

            //Turn Source StrongHold Green
            selectedInfo.GetRenderComponent().material.shader = Shader.Find("Outlined/UltimateOutline");
            selectedInfo.GetRenderComponent().material.SetColor("_FirstOutlineColor", Color.green);
            selectedInfo.GetRenderComponent().material.SetColor("_SecondOutlineColor", Color.green);
        }
        else if (source)
        {
            ObjectOwnerState sourceInfo = source.GetComponent <ObjectOwnerState>();

            //Turn Selected StrongHold Red
            selectedInfo.GetRenderComponent().material.shader = Shader.Find("Outlined/UltimateOutline");
            selectedInfo.GetRenderComponent().material.SetColor("_FirstOutlineColor", Color.red);
            selectedInfo.GetRenderComponent().material.SetColor("_SecondOutlineColor", Color.red);

            // If source is owned by a player, and not the same as target, send unit
            if (sourceInfo.player != null && source != selected)
            {
                SendUnit(sourceInfo, selected);
            }

            //Turn Source Back to Neutral
            sourceInfo.GetRenderComponent().material.shader = Shader.Find("Standard");
            source = null;
        }
    }
Beispiel #3
0
    private void ComputeResult(Collider unit)
    {
        ObjectOwnerState unitInfo       = unit.gameObject.GetComponent <ObjectOwnerState>();
        ObjectOwnerState strongholdInfo = GetComponent <ObjectOwnerState>();

        int newMagnitude;
        int unitMagnitude       = unitInfo.GetMagnitude();
        int strongholdMagnitude = strongholdInfo.GetMagnitude();

        if (strongholdInfo.player == unitInfo.player)
        {
            // Reinforcements arrived!
            newMagnitude = strongholdMagnitude + unitMagnitude;
        }
        else
        {
            // Stronghold is being attacked!
            newMagnitude = strongholdMagnitude - unitMagnitude;

            // If this stronghold is lost to the other player
            if (newMagnitude < 0)
            {
                strongholdInfo.player = unitInfo.player;
                strongholdInfo.UpdateColor();
            }
        }

        //New Magnitude
        strongholdInfo.SetMagnitude(Math.Abs(newMagnitude));

        //Remove Target Outl()ine Color
        strongholdInfo.GetRenderComponent().material.shader = Shader.Find("Standard");


        // Remove unit from scene
        Destroy(unit.gameObject);
    }
 public void Start()
 {
     displayMagnitude = gameObject.GetComponent <TextMeshPro>();
     objectState      = transform.parent.gameObject.GetComponent <ObjectOwnerState>();
     UpdateText();
 }