// Update is called once per frame void Update() { CheckEvader(); if (isNeedStat) { if (stat.GetAlive()) { if (canFight) { if (!combStat.IsAttacking()) { Moving(); } else { _animator.SetFloat("Speed", 0); } } else { Moving(); } } } else { Moving(); } }
// Update is called once per frame void Update() { coolNow -= Time.deltaTime; if (stat.GetAlive()) { if (isBuilding) { BuildingSystem bui = GetComponent <BuildingSystem>(); if (bui.CheckFinish()) { CheckTarget(); } else { target = null; } } else { CheckTarget(); } } else { target = null; } }
// 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; } }
// 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; } } }
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); } }
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++; } } }
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); } } } }
// 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; } }