void Update() { if (now == Now.Ready) { if (GM.IsPressedMouseButton == false) { vecPos = GM.GetTargetPos; vecPos.y = transform.position.y; var tempPosition = vecPos; Debug.Log(tempPosition); if (!Mathf.Approximately(vecPos.x, 0) || !Mathf.Approximately(vecPos.z, 0)) { tempPosition.x = tempPosition.x - (tempPosition.x % 5); // -5f; tempPosition.z = tempPosition.z - (tempPosition.z % 5); // -5f; if (Mathf.Approximately(tempPosition.x % 10, 0)) { tempPosition.x += 5; } if (Mathf.Approximately(tempPosition.z % 10, 0)) { tempPosition.z += 5; } transform.position = tempPosition; } } if (GM.IsPressedMouseButton == true) { now = Now.Move; AlphaChange(1f); gameObject.GetComponent <Collider>().enabled = true; } } if (now == Now.Move) { if (Health <= 0) { Destroy(this.gameObject); } Ray ray = new Ray(this.gameObject.transform.position, Vector3.forward); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, Range))//&& hit.collider.tag != "ground") { Target = hit.collider.gameObject; GivingDamage = Target.GetComponent <UnitLifeCycle>(); now = Now.Attack; Debug.Log(hit.transform.name); } anime.SetBool("Move", true); transform.Translate(Vector3.forward.normalized * Speed * Time.deltaTime);//, Space.World); } if (now == Now.Attack) { if (Health <= 0) { Destroy(this.gameObject); } if (IsHit == false) { IsHit = true; anime.speed = 0.5f; anime.SetBool("Attack", true); StartCoroutine("Attack", AttackSpeed); } Ray ray = new Ray(this.gameObject.transform.position, Vector3.forward); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, Range))//&& hit.collider.tag != "ground") { Target = hit.collider.gameObject; Debug.Log(hit.transform.name); } if (!Physics.Raycast(ray.origin, ray.direction, out hit, Range))//&& hit.collider.tag != "ground") { anime.speed = 1f; anime.SetBool("IsAttacking", false); now = Now.Move; } } }
void Awake() { UC = GetComponent <UnitLifeCycle>(); }