void Update() { if (Time.time - nextEarthSkill >= TIME_COUNTDOWN_SKILL_EARTH && checkAttack) { MessageAttack(); } if (isDestroyed == null) { checkAttack = false; } if (Input.GetMouseButtonDown(0) && chooseHero.isChoosedGameObject) { Ray clickedPosition = Camera.main.ScreenPointToRay(Input.mousePosition); targetPosition = new Vector2(clickedPosition.origin.x, clickedPosition.origin.y); chooseHero.SetIsChoosed(false); Instantiate(effectLocationTouch, targetPosition, Quaternion.Euler(new Vector3(0f, 0f, 0f))); } if (!checkAttack) { transform.position = Vector2.MoveTowards(transform.position, targetPosition, speedMove * Time.deltaTime); AnimationsHeroMove(targetPosition); } if (new Vector2(transform.position.x, transform.position.y) == targetPosition && !checkAttack) { es.AnimationIdle(); checkIdle = true; } else if (new Vector2(transform.position.x, transform.position.y) != targetPosition) { checkIdle = false; checkAttack = false; } }
void Update() { GetEnemyToAttack(); checkLevelHero(); if (gameObject == GameObject.FindWithTag("NagaInllusion") && Time.time - timeStartInllusion > TIME_EXIST_INLLUSION) { Destroy(gameObject); } if (gameObject != GameObject.FindWithTag("NagaInllusion") && Time.time - timeStartInllusion > 0f) { Instantiate(nagaInllusion, positionFire.transform.position, Quaternion.Euler(new Vector3(0f, 0f, 0f))); timeStartInllusion = Time.time + TIME_COUNTDOWN_SKILL_INLLUSION; } if (enemyChoosedToAttack != null) { float distance = Vector2.Distance(gameObject.transform.position, enemyChoosedToAttack.transform.position); if (distance > RANGE) { enemyChoosedToAttack = null; } } if (enemyChoosedToAttack == null && isIdle) { isAttack = false; AnimationIdle(); isIdle = false; } if (new Vector2(transform.position.x, transform.position.y) == touchPosition && !isAttack) { isIdle = true; } if (Input.GetMouseButtonDown(0) && chooseHero != null && chooseHero.isChoosedGameObject) { Ray clickedPosition = Camera.main.ScreenPointToRay(Input.mousePosition); touchPosition = new Vector2(clickedPosition.origin.x, clickedPosition.origin.y); chooseHero.SetIsChoosed(false); Instantiate(effectLocationTouch, touchPosition, Quaternion.Euler(new Vector3(0f, 0f, 0f))); } if (!isAttack && !isIdle) { transform.position = Vector2.MoveTowards(transform.position, touchPosition, speedMove * Time.deltaTime); AnimationsHeroMove(touchPosition); } if (new Vector2(transform.position.x, transform.position.y) != touchPosition) { isIdle = false; isAttack = false; } if (isAttack && enemyChoosedToAttack != null) { if (transform.position.x < enemyChoosedToAttack.transform.position.x) { RotateLeftHero(); } else { RotateRightHero(); } } if (Time.time - timeStartAddHearth >= TIME_ADD_HEALTH) { AddHealthPerTime(); timeStartAddHearth = Time.time + TIME_ADD_HEALTH; } }