public void handleWalk() { if (GetComponent<EnemyScript>()) { mode = SoldierMode.AGGRESSIVE; } if (targetEnemy && mode == SoldierMode.AGGRESSIVE && Vector3.Distance(transform.position, targetEnemy.transform.position) < 0.2F) { anim.SetBool("attacking", true); if (Time.time > t0 + 1f) { if (targetEnemy.name == "HDV_Ork") { if (name == "OrcSoldier(Clone)") { targetEnemy = null; return; } targetEnemy.GetComponent<TownHallScript>().handleDefense(); } targetEnemy.GetComponent<MapObject>().hp -= 1; t0 = Time.time; } } else { Vector3 currentTarget = (targetEnemy && mode == SoldierMode.AGGRESSIVE) ? targetEnemy.transform.position : targetPosition; if (transform.position != currentTarget) { anim.SetBool("attacking",false); anim.SetBool("walking", true); transform.position = Vector3.MoveTowards(transform.position, currentTarget, Time.deltaTime); transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.position - currentTarget); } else { anim.SetBool("walking",false); } } }
public void handleTag(GameObject target) { if (target.tag != this.tag) { if (gameObject != target) { mode = SoldierMode.AGGRESSIVE; targetEnemy = target; } } else { setPassive(); } }
public void handleWalk() { if (GetComponent <EnemyScript>()) { mode = SoldierMode.AGGRESSIVE; } if (targetEnemy && mode == SoldierMode.AGGRESSIVE && Vector3.Distance(transform.position, targetEnemy.transform.position) < 0.2F) { anim.SetBool("attacking", true); if (Time.time > t0 + 1f) { if (targetEnemy.name == "HDV_Ork") { if (name == "OrcSoldier(Clone)") { targetEnemy = null; return; } targetEnemy.GetComponent <TownHallScript>().handleDefense(); } targetEnemy.GetComponent <MapObject>().hp -= 1; t0 = Time.time; } } else { Vector3 currentTarget = (targetEnemy && mode == SoldierMode.AGGRESSIVE) ? targetEnemy.transform.position : targetPosition; if (transform.position != currentTarget) { anim.SetBool("attacking", false); anim.SetBool("walking", true); transform.position = Vector3.MoveTowards(transform.position, currentTarget, Time.deltaTime); transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.position - currentTarget); } else { anim.SetBool("walking", false); } } }
public void setPassive() { mode = SoldierMode.PASSIVE; targetEnemy = null; }