Ejemplo n.º 1
0
 void TrainingUnit()
 {
     if (isTraining)
     {
         cancelUI.gameObject.SetActive(true);
         barUI.gameObject.SetActive(true);
         if (cancelUI.CheckClick())
         {
             cancelUI.SetClick(false);
             isTraining = false;
         }
         if (trainTimeNow >= trainTimeMax)
         {
             isTraining = false;
             GameObject      unit  = Instantiate(unitTrainNow, spawnPoint.transform.position, spawnPoint.transform.rotation) as GameObject;
             UnitGroupSystem group = unit.GetComponent <UnitGroupSystem>();
             if (group != null)
             {
                 group.SetOwner(build.GetOwner());
             }
             WorkerUnit worker = unit.GetComponent <WorkerUnit>();
             if (worker != null)
             {
                 worker.SetOwner(this.build.GetOwner());
             }
         }
         trainTimeNow += Time.deltaTime;
         barUI.SetProgress(trainTimeNow / trainTimeMax);
     }
     else
     {
         cancelUI.gameObject.SetActive(false);
         barUI.gameObject.SetActive(false);
         VRPlayerIndicator player = null;
         foreach (GameObject plays in GameObject.FindGameObjectsWithTag("Player"))
         {
             VRPlayerIndicator ind = plays.GetComponent <VRPlayerIndicator>();
             if (ind.GetPlayerNumber() == stat.GetOwner())
             {
                 player = ind;
             }
         }
         for (int i = 0; i < trainUI.Length; i++)
         {
             if (trainUI[i].CheckClick() && player.GetEther() >= trainCost[i])
             {
                 isTraining   = true;
                 unitTrainNow = trainUnit[i];
                 trainTimeMax = trainTime[i];
                 trainTimeNow = 0;
                 player.ChangeEther(-trainCost[i]);
                 barUI.SetProgress(0);
                 trainUI[i].SetClick(false);
                 Debug.Log("Start Training!!!");
             }
         }
     }
 }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     coolNow -= Time.deltaTime;
     if (stat.GetAlive() && autoATKEnabled)
     {
         if (target != null)
         {
             Vector3    unitPos   = new Vector3(transform.position.x, 0, transform.position.z);
             Vector3    targetPos = new Vector3(target.transform.position.x, 0, target.transform.position.z);
             RaycastHit hit;
             bool       isCol = false;
             if (Physics.Raycast(transform.position + transform.up, transform.TransformDirection(Vector3.forward), out hit, atkRange))
             {
                 GameObject hitObject = hit.transform.gameObject;
                 if (hitObject == target.gameObject)
                 {
                     isCol = true;
                 }
             }
             if (Vector3.Distance(unitPos, targetPos) <= atkRange || isCol)
             {
                 UnitMove uni = GetComponent <UnitMove>();
                 uni.OrderMove(Vector3.one);
                 this.transform.LookAt(target.transform);
                 this.transform.rotation = Quaternion.Euler(0, this.transform.eulerAngles.y, 0);
                 CommandATK();
             }
             else
             {
                 UnitMove mover = GetComponent <UnitMove>();
                 mover.OrderMove(target.transform.position);
             }
             if (target == null || !target.GetAlive())
             {
                 target = null;
             }
         }
         else
         {
             Collider[] hitColliders = Physics.OverlapSphere(transform.position, atkNotice);
             int        i            = 0;
             while (i < hitColliders.Length)
             {
                 UnitStatSystem enemyStat = hitColliders[i].GetComponent <UnitStatSystem>();
                 if (enemyStat != null && stat.GetOwner() != enemyStat.GetOwner() && !AllianceSystem.CheckAlly(stat.GetOwner(), enemyStat.GetOwner()) && enemyStat.GetAlive())
                 {
                     target = enemyStat;
                     Debug.Log("Found Enemy");
                 }
                 i++;
             }
         }
     }
     else
     {
         target = null;
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
    private IEnumerator aquireATK()
    {
        //projPoint.transform.LookAt(target.transform);
        if (soundEffect)
        {
            Instantiate(soundEffect, transform.position, transform.localRotation);
        }
        ProjectieDummy proj = Instantiate(missile, projPoint.transform.position, projPoint.transform.rotation) as ProjectieDummy;

        if (target != null)
        {
            //proj.transform.LookAt(target.transform.position);
            Debug.Log("Throw to Target");
            proj.StartProj(target.transform.position, stat.GetOwner(), damage);
        }
        else
        {
            //proj.transform.LookAt(transform.position + (transform.forward * atkRange));
            Debug.Log("Throw to Point");
            proj.StartProj(transform.position + (transform.forward * atkRange), stat.GetOwner(), damage);
        }

        yield return(null);
    }
    void Construction()
    {
        VRPlayerIndicator player = null;

        foreach (GameObject plays in GameObject.FindGameObjectsWithTag("Player"))
        {
            VRPlayerIndicator ind = plays.GetComponent <VRPlayerIndicator>();
            if (ind.GetPlayerNumber() == stat.GetOwner())
            {
                player = ind;
            }
        }
        for (int i = 0; i < buildUI.Length; i++)
        {
            if (buildUI[i].CheckClick() && player.GetEther() >= buildCost[i])
            {
                InGameFirstHand hand   = buildUI[i].GetHandClicked();
                ConstructDummy  dumNow = Instantiate(dummy[i], this.transform.position, this.transform.rotation) as ConstructDummy;
                dumNow.StartDummy(buildUnit[i].GetModel(), buildUnit[i], stat.GetOwner(), buildCost[i]);
                hand.SelectConstruction(dumNow);
                buildUI[i].SetClick(false);
            }
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        stat = GetComponent <UnitStatSystem>();
        VRPlayerIndicator player = null;

        foreach (GameObject plays in GameObject.FindGameObjectsWithTag("Player"))
        {
            VRPlayerIndicator ind = plays.GetComponent <VRPlayerIndicator>();
            if (ind.GetPlayerNumber() == stat.GetOwner())
            {
                player = ind;
            }
        }
        etherText.text = "Ether : " + player.GetEther();
    }
    void OnTriggerEnter(Collider other)
    {
        UnitStatSystem uni = other.gameObject.GetComponent <UnitStatSystem>();

        if ((uni != null && uni.GetOwner() != ownerNum && !AllianceSystem.CheckAlly(ownerNum, uni.GetOwner())) || other.gameObject.tag == "Terrain")
        {
            if (uni != null && uni.GetAlive())
            {
                uni.GetDamage(damage);
            }
            if (soundEff)
            {
                Instantiate(soundEff, transform.position, transform.localRotation);
            }
            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 8
0
 private void CheckTarget()
 {
     if (target != null)
     {
         Vector3 unitPos   = new Vector3(transform.position.x, 0, transform.position.z);
         Vector3 targetPos = new Vector3(target.transform.position.x, 0, target.transform.position.z);
         if (Vector3.Distance(unitPos, targetPos) <= atkRange)
         {
             projPoint.transform.LookAt(target.transform);
             //projPoint.transform.rotation = Quaternion.Euler(0, projPoint.transform.eulerAngles.y, 0);
             StartAttack();
         }
         else
         {
             target = null;
         }
         if (target == null || !target.GetAlive())
         {
             target = null;
         }
     }
     else
     {
         Collider[] hitColliders = Physics.OverlapSphere(transform.position, atkNotice);
         int        i            = 0;
         while (i < hitColliders.Length)
         {
             UnitStatSystem enemyStat = hitColliders[i].GetComponent <UnitStatSystem>();
             if (enemyStat != null && stat.GetOwner() != enemyStat.GetOwner() && !AllianceSystem.CheckAlly(stat.GetOwner(), enemyStat.GetOwner()) && enemyStat.GetAlive())
             {
                 target = enemyStat;
                 Debug.Log("Found Enemy");
             }
             i++;
         }
     }
 }
Ejemplo n.º 9
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);
                }
            }
        }
    }
    private void CheckArmy()
    {
        foreach (UnitGroupSystem army in armyList)
        {
            if (!army)
            {
                armyList.Remove(army);
                Destroy(army.gameObject);
            }
        }

        foreach (UnitGroupSystem army in armyList)
        {
            GameObject target       = null;
            Collider[] hitColliders = Physics.OverlapSphere(army.transform.position, 50);
            int        i            = 0;
            while (i < hitColliders.Length)
            {
                UnitStatSystem tarStat = hitColliders[i].GetComponent <UnitStatSystem>();
                if (tarStat && tarStat.GetAlive() && tarStat.GetOwner() != playerStat.GetPlayerNumber() && !AllianceSystem.CheckAlly(playerStat.GetPlayerNumber(), tarStat.GetOwner()))
                {
                    target = tarStat.gameObject;
                }
                else
                {
                    UnitGroupSystem tarGroup = hitColliders[i].GetComponent <UnitGroupSystem>();
                    if (tarGroup && tarGroup.GetOwner() != playerStat.GetPlayerNumber() && !AllianceSystem.CheckAlly(playerStat.GetPlayerNumber(), tarGroup.GetOwner()))
                    {
                        target = tarGroup.gameObject;
                    }
                }
                i++;
            }
            if (target && !army.HaveTarget())
            {
                army.SetAutoAttaack(true);
                army.SetTarget(target);
            }
            else
            {
                if (armyList.Count >= 3)
                {
                    UnitStatSystem[] tarG = FindObjectsOfType <UnitStatSystem>();
                    foreach (UnitStatSystem tarDum in tarG)
                    {
                        if (tarDum && tarDum.GetAlive() && tarDum.GetOwner() != playerStat.GetPlayerNumber() && !AllianceSystem.CheckAlly(playerStat.GetPlayerNumber(), tarDum.GetOwner()))
                        {
                            target = tarDum.gameObject;
                        }
                    }
                    if (target)
                    {
                        army.GetComponent <UnitMove>().OrderMove(target.transform.position);
                    }
                }
                else
                {
                    GameObject posDummy = Instantiate(aiPointDummy, aiStronghold.transform.position, aiStronghold.transform.rotation) as GameObject;
                    posDummy.transform.Rotate(new Vector3(0, Random.Range(135f, 225f), 0));
                    posDummy.transform.position += posDummy.transform.forward * Random.Range(40, 50);
                    army.GetComponent <UnitMove>().OrderMove(posDummy.transform.position);
                    //army.GetComponent<UnitMove>().OrderMove(Vector3.one);
                }
            }
        }
    }
Ejemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     stat = GetComponent <UnitStatSystem>();
     stat.SetOwner(stat.GetOwner());
 }
    // 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;
            }
        }
    }
Ejemplo n.º 13
0
    // 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;
        }
    }
Ejemplo n.º 14
0
    private void Moving()
    {
        Vector3 movement    = Vector3.zero;
        Vector3 adjustedPos = new Vector3();

        if (isColEvd)
        {
            adjustedPos = new Vector3(evdPoints[0].transform.position.x, transform.position.y, evdPoints[0].transform.position.z);
        }
        else
        {
            adjustedPos = new Vector3(_targetPos.x, transform.position.y, _targetPos.z);
        }


        if (_targetPos != Vector3.one)
        {
            Quaternion targetRot = Quaternion.LookRotation(adjustedPos - transform.position);
            //
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, rotSpeed * Time.deltaTime);

            movement = _curSpeed * Vector3.forward;
            movement = transform.TransformDirection(movement);
        }

        if (isColEvd)
        {
        }
        else
        {
            //Debug.Log(Vector3.Distance(adjustedPos, transform.position));
            if (Vector3.Distance(adjustedPos, transform.position) < targetBuffer)
            {
                _curSpeed -= deceleration * Time.deltaTime;
                if (_curSpeed <= 0)
                {
                    _targetPos = Vector3.one;
                }
            }
        }


        if (needAni)
        {
            _animator.SetFloat("Speed", movement.sqrMagnitude);
        }


        movement *= Time.deltaTime;
        _charController.Move(movement);

        if (isColEvd)
        {
            CollisionEvading();
        }
        else
        {
            RaycastHit hit;
            GameObject hitObject = null;

            Debug.DrawRay(checkColPoint.transform.position + (transform.up * 2), checkColPoint.transform.TransformDirection(Vector3.forward) * colCheckDistance, Color.blue);
            if (Physics.Raycast(checkColPoint.transform.position + transform.up, checkColPoint.transform.TransformDirection(Vector3.forward), out hit, colCheckDistance))
            {
                Debug.Log("Raycast Hit");
                hitObject = hit.transform.gameObject;
                UnitMove colUnit = hitObject.gameObject.GetComponent <UnitMove>();

                if (colUnit)
                {
                    UnitStatSystem colUnitStat = colUnit.GetComponent <UnitStatSystem>();
                    if (colUnitStat && colUnitStat.GetOwner() == stat.GetOwner())
                    {
                        if (colUnit.GetCurrentSpeed() < _curSpeed)
                        {
                            if (evdPoints.Count == 0)
                            {
                                //StartColEvade();
                            }
                        }
                    }
                    else
                    {
                        UnitGroupSystem colGroup = hitObject.GetComponent <UnitGroupSystem>();
                        if (colGroup && colGroup.GetOwner() == stat.GetOwner())
                        {
                            if (evdPoints.Count == 0)
                            {
                                //StartColEvade();
                            }
                        }
                    }
                }
                else
                {
                    if (evdPoints.Count == 0)
                    {
                        //StartColEvade();
                    }
                }
            }
            else
            {
                isColEvd = false;
            }
        }
    }