Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     constructEff.SetActive(!buildingFinished);
     foreach (Transform child in constructEff.transform)
     {
         child.gameObject.SetActive(!buildingFinished);
     }
     stat.SetSelected(isSelected);
     if (isSelected)
     {
         selectorCircle.SetActive(true);
         baseUI.SetActive(true);
         VRPlayerIndicator player = null;
         foreach (GameObject plays in GameObject.FindGameObjectsWithTag("Player"))
         {
             VRPlayerIndicator ind = plays.GetComponent <VRPlayerIndicator>();
             if (ind.GetPlayerNumber() == stat.GetOwner())
             {
                 player = ind;
             }
         }
         VRHeadTracking head = player.GetComponent <VRHeadTracking>();
         baseUI.transform.LookAt(head.GetHead().transform);
         if (!buildingFinished)
         {
             cancelUI.gameObject.SetActive(true);
             barUI.gameObject.SetActive(true);
         }
         else
         {
             cancelUI.gameObject.SetActive(false);
             barUI.gameObject.SetActive(false);
         }
     }
     else
     {
         selectorCircle.SetActive(false);
         baseUI.gameObject.SetActive(false);
     }
     if (cancelUI.CheckClick())
     {
         cancelUI.SetClick(false);
         Destroy(this.gameObject);
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (isSelected)
        {
            selectorCircle.SetActive(true);
        }
        else
        {
            selectorCircle.SetActive(false);
        }

        for (int i = 0; i < unitList.Count; i++)
        {
            GameObject uniChe = null;
            uniChe = unitList[i];
            if (uniChe)
            {
                UnitStatSystem uniSta = uniChe.GetComponent <UnitStatSystem>();
                uniSta.SetSelected(isSelected);
            }
        }

        if (target != null)
        {
            Vector3  targetPos = new Vector3(target.transform.position.x, 0, target.transform.position.z);
            Vector3  groPos    = new Vector3(transform.position.x, 0, transform.position.z);
            UnitMove mover     = GetComponent <UnitMove>();
            if (Vector3.Distance(targetPos, groPos) >= atkRange)
            {
                if (!mover.GetIsColEvd())
                {
                    mover.OrderMove(targetPos);
                }
            }
            else
            {
                if (!mover.GetIsColEvd())
                {
                    mover.OrderMove(Vector3.one);
                }
            }
        }
        else
        {
            for (int i = 0; i < unitList.Count; i++)
            {
                GameObject uniObj = null;
                uniObj = unitList[i];
                GameObject posObj = null;
                posObj = pointList[i];
                if (uniObj != null && posObj != null)
                {
                    Vector3        uniPos = new Vector3(uniObj.transform.position.x, 0, uniObj.transform.position.z);
                    Vector3        posPos = new Vector3(posObj.transform.position.x, 0, posObj.transform.position.z);
                    UnitMove       uni    = uniObj.GetComponent <UnitMove>();
                    UnitCombat     com    = uniObj.GetComponent <UnitCombat>();
                    UnitStatSystem star   = uniObj.GetComponent <UnitStatSystem>();
                    if (star.GetAlive())
                    {
                        star.SetSelected(isSelected);
                        if (!com.HaveTarget())
                        {
                            if (Vector3.Distance(uniPos, posPos) > 1)
                            {
                                if (!uni.GetIsColEvd())
                                {
                                    uni.OrderMove(posObj.transform.position);
                                    com.SetAutoATK(false);
                                }
                            }
                            else
                            {
                                if (!uni.GetIsColEvd())
                                {
                                    uni.OrderMove(Vector3.one);
                                    com.SetAutoATK(true);
                                }
                            }
                        }
                        else
                        {
                            Vector3 groPos = new Vector3(transform.position.x, 0, transform.position.z);
                            if (Vector3.Distance(groPos, uniPos) >= maxFollow)
                            {
                                com.SetTarget(null);
                                com.SetAutoATK(false);
                            }
                        }
                    }
                }
                else
                {
                    unitList.Remove(uniObj);
                    pointList.Remove(posObj);
                    Destroy(posObj.gameObject);
                }
            }
        }

        if (unitList.Count <= 0)
        {
            Destroy(this.gameObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        stat.SetSelected(isSelected);
        if (isSelected)
        {
            selectorCircle.SetActive(true);
        }
        else
        {
            selectorCircle.SetActive(false);
        }

        etherModel.SetActive(etherHarvested > 0);

        harvestCool -= Time.deltaTime;

        if (stat.GetAlive() && etherTarget != null)
        {
            if (etherHarvested < 100)
            {
                UnitMove mover = GetComponent <UnitMove>();
                if (Vector3.Distance(this.transform.position, etherTarget.transform.position) <= 5)
                {
                    mover.StopMove();
                    this.transform.LookAt(etherTarget.transform);
                    this.transform.rotation = Quaternion.Euler(0, this.transform.eulerAngles.y, 0);
                    if (harvestCool <= 0)
                    {
                        harvestCool = timePerHarvest;
                        StartCoroutine(Harvest());
                    }
                }
                else
                {
                    mover.OrderMove(etherTarget.transform.position);
                }
            }
            else
            {
                if (returnBuild == null)
                {
                    float returnRange = 999999999999f;
                    foreach (ResourceReturnPoint ret in GameObject.FindObjectsOfType <ResourceReturnPoint>())
                    {
                        UnitStatSystem retSta = ret.GetComponent <UnitStatSystem>();
                        if (stat.GetOwner() == retSta.GetOwner() && Vector3.Distance(this.transform.position, ret.transform.position) <= returnRange)
                        {
                            returnRange = Vector3.Distance(this.transform.position, ret.transform.position);
                            returnBuild = ret;
                        }
                    }
                }
                else
                {
                    UnitMove mover = GetComponent <UnitMove>();
                    mover.OrderMove(returnBuild.transform.position);
                }
            }
        }
        if (stat.GetAlive() && returnBuild != null && Vector3.Distance(this.transform.position, returnBuild.transform.position) <= returnBuild.GetReturnRange())
        {
            VRPlayerIndicator player = null;
            foreach (GameObject plays in GameObject.FindGameObjectsWithTag("Player"))
            {
                VRPlayerIndicator ind = plays.GetComponent <VRPlayerIndicator>();
                if (ind.GetPlayerNumber() == stat.GetOwner())
                {
                    player = ind;
                }
            }
            player.ChangeEther(etherHarvested);
            etherHarvested = 0;
        }
    }