// Update is called once per frame
    void Update()
    {
        int inRange = 0;

        if (needRange)
        {
            Collider[] hitColliders = Physics.OverlapSphere(transform.position, 40);
            int        i            = 0;
            while (i < hitColliders.Length)
            {
                UnitStatSystem buildingStat = hitColliders[i].GetComponent <UnitStatSystem>();
                if (buildingStat && buildingStat.GetAlive() && buildingStat.GetUnitType() == UnitStatSystem.UnitObjectType.Building && buildingStat.GetOwner() == thisOwner)
                {
                    inRange++;
                }
                if (buildingStat && buildingStat.GetAlive() && buildingStat.GetUnitType() == UnitStatSystem.UnitObjectType.Building && buildingStat.GetOwner() != thisOwner)
                {
                    inRange--;
                }
                i++;
            }
        }
        else
        {
            inRange = 1;
        }
        buildable = (onGround) && (collideNow <= 0) && (inRange >= 1);
        Debug.Log("I have collicion at : " + collideNow);
        if (buildable)
        {
            foreach (Transform child in models.transform)
            {
                GameObject childOBJ = child.gameObject;
                childOBJ.GetComponent <Renderer>().material = buildableMat;
            }
        }
        else
        {
            foreach (Transform child in models.transform)
            {
                GameObject childOBJ = child.gameObject;
                childOBJ.GetComponent <Renderer>().material = unbuildableMat;
            }
        }
    }
Exemplo n.º 2
0
    void CheckUnitOBJ(GameObject hitObject)
    {
        UnitStatSystem unit = hitObject.GetComponent <UnitStatSystem>();

        if (unit != null)
        {
            Debug.Log("SELECT UNIT");
            if (unit.GetUnitType() == UnitStatSystem.UnitObjectType.Building)
            {
                Debug.Log("SELECT Building");
                BuildingSystem buil = hitObject.GetComponent <BuildingSystem>();
                if (player.GetPlayerNumber() == buil.GetOwner())
                {
                    Debug.Log("Select Own Building");
                    UnselectUnit();
                    UnselectWorker();
                    if (buil != selectedBuilding)
                    {
                        UnselectBuilding();
                        SelectBuilding(buil);
                    }
                }
            }
            if (unit.GetUnitType() == UnitStatSystem.UnitObjectType.Units)
            {
                WorkerUnit wor = unit.GetComponent <WorkerUnit>();
                if (wor != null)
                {
                    if (player.GetPlayerNumber() == wor.GetOwner())
                    {
                        UnselectUnit();
                        UnselectBuilding();
                        if (wor != selectedWorker)
                        {
                            UnselectWorker();
                            SelectWorker(wor);
                        }
                    }
                }
            }
            if (unit.GetOwner() != player.GetPlayerNumber() && selectedUnit != null)
            {
                if (!AllianceSystem.CheckAlly(player.GetPlayerNumber(), unit.GetOwner()))
                {
                    Debug.Log("ATTACK");
                    selectedUnit.SetAutoAttaack(true);
                    selectedUnit.SetTarget(unit.gameObject);
                }
            }
        }
        if (hitObject.tag == "Soldier Group")
        {
            Debug.Log("SELECT SOLDIER");
            UnitGroupSystem unitGro = hitObject.GetComponent <UnitGroupSystem>();
            if (player.GetPlayerNumber() == unitGro.GetOwner())
            {
                Debug.Log("Select own Soldier");
                UnselectBuilding();
                UnselectWorker();
                if (unitGro != selectedUnit)
                {
                    UnselectUnit();
                    SelectUnit(unitGro);
                }
            }
            if (unitGro.GetOwner() != player.GetPlayerNumber() && selectedUnit != null)
            {
                if (!AllianceSystem.CheckAlly(player.GetPlayerNumber(), unitGro.GetOwner()))
                {
                    Debug.Log("ATTACK");
                    selectedUnit.SetAutoAttaack(true);
                    selectedUnit.SetTarget(unitGro.gameObject);
                }
            }
        }
    }