// Update is called once per frame void Update() { if (HealthScript.getDead() == false) { transform.position = new Vector3(transform.position.x, transform.position.y + Mathf.Sin(Time.time * FloatSpeed) / FloatDistanceDivider, transform.position.z); isIdling = true; if (isIdling == true && MyAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { MyAnimation.Play("Idle", 0, 0.0f); } if (FadeIn == true) { if (AuraFader + 0.8f * Time.deltaTime < 1.0f) { AuraFader += 0.8f * Time.deltaTime; } else { FadeIn = false; } } else if (FadeIn == false) { if (AuraFader - 0.8f * Time.deltaTime > 0.0f) { AuraFader -= 0.8f * Time.deltaTime; } else { FadeIn = true; } } Aura.GetComponent <SpriteRenderer> ().color = new Color(1f, 1f, 1f, AuraFader); } }
//IEnumerator StopFlinch(){ // yield return new WaitForSeconds (0.3f); // vel = Vector2.zero; //CanControl = true; /// StopCoroutine (StopFlinch ()); //} void Update() { // Debug.Log (vel.y); if (GameManager.CutsceneEnabled == false) { if (ControllerScript.getTimeControl() == false) { //Apply Gravity if (!controller.isGrounded || vel.y > 0) { vel.y -= Time.deltaTime * 80; } else { vel.y = -1; } if (isFlinching) { // shooting = false; //counter = 0.0f; //i = 0; //StopCoroutine (shootBullet ()); } if (isFlinching == true && vel.y < 0 && controller.isGrounded) { vel = Vector2.zero; CanControl = true; isFlinching = false; } if (CanControl == true) { //here we check the distance away the player is from the enemy float distance = target.transform.position.x - transform.position.x; float ydistance = target.transform.position.y - transform.position.y; if (distance < 0) { distance *= -1; } if (ydistance < 0) { ydistance *= -1; } if (target.transform.position.x > transform.position.x) { transform.localScale = new Vector3(origX, transform.localScale.y, transform.localScale.z); right = true; } if (target.transform.position.x < transform.position.x) { transform.localScale = new Vector3(-origX, transform.localScale.y, transform.localScale.z); right = false; } if (bulletScript.getBulletActive() == true && bulletScript.getLifeCounter() > bulletScript.getBulletLife()) { HideBullet(); } if (bulletScript.getBulletActive() == false && HealthScript.getDead() == false && playerHealth.Dead == false) { //if the player is close enough. the enemy can start animating and doing its thing. if (distance < 16 && ydistance < 8) { // Debug.Log (counter); counter += Time.deltaTime * frameRate; if (distance > 9 && distance < 16 && !shooting) { if (target.transform.position.x < transform.position.x) { vel.x = -runSpeed; } if (target.transform.position.x > transform.position.x) { vel.x = runSpeed; } if (counter > i && i < run.Length) { rend.sprite = run [i]; i += 1; } if (counter > run.Length) { counter = 0.0f; i = 0; } } if (shooting) { vel.x = 0; if (counter > i && i < shoot.Length) { rend.sprite = shoot [i]; i += 1; } } //the enemy will shoot a bullet only if the player is close enough and shooting is indeed false. if (distance < 9 && shooting == false && HealthScript.getDead() == false) { //ShowBullet(); StartCoroutine(shootBullet()); } } } } //if the enemy falls down a hole, we want to destroy it so it doesn't exist for no reason. if (transform.position.y < -10) { // Destroy (gameObject); } //Apply movement to player based on vel variable which is a Vector3. controller.Move(vel * Time.deltaTime); } else { } if (ControllerScript.getTimeControl()) { // isFlinching = false; } } }
// Update is called once per frame void Update() { //CanControl = false; if (ControllerScript.getTimeControl() == false) { if (HealthScript.getDead() == false) { //Gravity if (!controller.isGrounded) { vel.y -= Time.deltaTime * 80; jumpCounter += Time.deltaTime; } else { vel.y = -1; jumpCounter = 0.0f; } if (GameManager.CutsceneEnabled == false) { if (isFlinching == true && vel.y < 0 && controller.isGrounded) { vel = Vector2.zero; CanControl = true; isFlinching = false; } if (CanControl == true) { //here we check the distance away the player is from the enemy float distance = target.transform.position.x - transform.position.x; float ydistance = target.transform.position.y - transform.position.y; if (distance < 0) { distance *= -1; } if (ydistance < 0) { ydistance *= -1; } if (target.transform.position.x > transform.position.x && transform.localScale.x == -1.0f && isAttacking == false) { State = "Idle"; //StartMoving = false; StopAllExcept(isIdling); isIdling = true; MyAnimation.SetBool("isIdle", isIdling); transform.localScale = new Vector3(origX, transform.localScale.y, transform.localScale.z); right = true; } if (target.transform.position.x < transform.position.x && transform.localScale.x == 1.0f && isAttacking == false) { State = "Idle"; //StartMoving = false; StopAllExcept(isIdling); isIdling = true; MyAnimation.SetBool("isIdle", isIdling); transform.localScale = new Vector3(-origX, transform.localScale.y, transform.localScale.z); right = false; } if (controller.isGrounded && vel.x == 0.0f) { /// StopAllExcept(isIdling); // isIdling = true; } if (controller.isGrounded && isFlinching == false && isIdling == true) { vel = new Vector2(0.0f, vel.y); } // if (HealthScript.getDead () == false && playerHealth.Dead == false) { //if the player is close enough. the enemy can start animating and doing its thing. if (distance < 16 && ydistance < 8) { counter += Time.deltaTime; if (distance >= 10 && isAttacking == false) { State = "Idle"; StopAllExcept(isIdling); isIdling = true; MyAnimation.SetBool("isIdle", isIdling); } if (distance < 2 && State != "Attacking") { StopAllExcept(isIdling); MyAnimation.SetBool("isIdle", true); State = "Attacking"; DelayTime = Time.time; } if (State == "Attacking") { ThisTime = Time.time; } if (State == "Attacking" && ThisTime > DelayTime + 1.0f && isAttacking == false) { StopAllExcept(isAttacking); //MyAnimation.SetBool("isIdle",true); isAttacking = true; MyAnimation.SetBool("isAttacking", true); MyAnimation.Play("Attack", 0, 0.0f); SlashWave.GetComponent <BoxCollider> ().enabled = true; SlashWave.GetComponent <SpriteRenderer> ().enabled = true; } if (isAttacking == true) { normalTime = MyAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime; if (MyAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { if (distance >= 2 || target.transform.position.x > transform.position.x && transform.localScale.x == -1.0f || target.transform.position.x < transform.position.x && transform.localScale.x == 1.0f) { State = "Idle"; StopAllExcept(isIdling); isIdling = true; isAttacking = false; MyAnimation.SetBool("isIdle", isIdling); } } } //MOVING if (distance < 10 && isAttacking == false && State != "Attacking" && State != "Moving") { StopAllExcept(isIdling); MyAnimation.SetBool("isIdle", true); State = "Moving"; DelayTime = Time.time; } if (State == "Moving") { ThisTime = Time.time; } if (State == "Moving" && ThisTime > DelayTime + 1.0f && isMoving == false) { StopAllExcept(isMoving); //MyAnimation.SetBool("isIdle",true); isMoving = true; MyAnimation.SetBool("isMoving", isMoving); } if (isMoving == true && MyAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { MyAnimation.Play("Move", 0, 0.0f); } if (isMoving == true && isAttacking == false && State != "Attacking") { normalTime = MyAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime; if (target.transform.position.x < transform.position.x) { vel.x = -runSpeed; } if (target.transform.position.x > transform.position.x) { vel.x = runSpeed; } } else { vel.x = 0.0f; } if (isIdling) { } //else{ //StopAllExcept(isIdling); //isIdling = true; //isMoving = false; //} // Debug.Log (distance); if (distance < 2.5f && ydistance < 2.5f) { if (!isFlinching) { } } if (distance > 9 && distance < 16 && !Attacking) { if (target.transform.position.x < transform.position.x) { // vel.x = -runSpeed; //Debug.Log (controller.isGrounded ); } if (target.transform.position.x > transform.position.x) { // vel.x = runSpeed; } // if (counter > i && i < run.Length) { // rend.sprite = run [i]; // i += 1; // } // if (counter > run.Length) { // counter = 0.0f; // i = 0; // } } if (Attacking) { // vel.x = 0; // if (counter > i && i < shoot.Length) { // rend.sprite = shoot [i]; // i += 1; // } } //the enemy will shoot a bullet only if the player is close enough and shooting is indeed false. // if (distance < 9 && Attacking == false && HealthScript.getDead () == false) { //ShowBullet(); // StartCoroutine (shootBullet ()); // } // } } } } controller.Move(vel * Time.deltaTime); } else { State = ""; StopAllExcept(isIdling); isIdling = false; MyAnimation.SetBool("isIdle", isIdling); MyAnimation.Play("Idle", 0, 0.0f); } } }