// 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; } }
public override void OnIndexTriggered() { base.OnIndexTriggered(); if (!startSelected) { startSelected = true; Debug.Log("Raycast Initated"); RaycastHit hit; GameObject hitObject = null; if (Physics.Raycast(pointer.transform.position, pointer.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity)) { hitObject = InitRayCast(hit); } if (selectedConstruct != null) { if (selectedConstruct.IsBuildable()) { selectedConstruct.ConfirmBuild(); selectedConstruct = null; } } else { CheckUnitOBJ(hitObject); CheckUIOBJ(hitObject); } EtherDeposit eth = hitObject.GetComponent <EtherDeposit>(); if (selectedWorker != null && eth != null) { selectedWorker.GoHarvest(eth); } if (hitObject.tag == "Terrain" && (selectedUnit != null || selectedWorker != null)) { UnitMove mover = null; if (selectedUnit != null) { mover = selectedUnit.GetComponent <UnitMove>(); selectedUnit.SetAutoAttaack(false); selectedUnit.SetTarget(null); } else if (selectedWorker != null) { mover = selectedWorker.GetComponent <UnitMove>(); selectedWorker.GoHarvest(null); } mover.OrderMove(hit.point); StartCoroutine(MovePointIndicator(hit.point)); } } }
private IEnumerator aquireATK() { isATKing = true; Animator ani = GetComponent <Animator>(); ani.SetBool("Attack", true); yield return(new WaitForSeconds(atkStartSwing)); if (soundEffect) { Instantiate(soundEffect, transform.position, transform.localRotation); } if (!rangedATK) { if (target != null) { target.GetDamage(damage); Instantiate(meleeEffect, target.transform.position + (transform.up * 2), transform.localRotation); } else { } } else { ProjectieDummy proj = Instantiate(missile, projPoint.transform.position, transform.localRotation) 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); } } ani.SetBool("Attack", false); yield return(new WaitForSeconds(atkStopSwing)); UnitMove uni = GetComponent <UnitMove>(); uni.OrderMove(Vector3.one); isATKing = false; yield return(null); }
// 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; } }