private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { spriteAnimator.ChangeAnimationState("NPC_ResistanceSoldierTalkRadius"); dialogueTrigger.allowEnable = true; inputManager.dialogueTrigger = dialogueTrigger; } }
public IEnumerator AnimateLight(float time) { float timeToBeat = Time.time + time; animator.ChangeAnimationState("BreakableLight_Damage", 0); while (timeToBeat > Time.time) { yield return(new WaitForEndOfFrame()); } animator.ChangeAnimationState("BreakableLight_Regen", 0); }
private void OnTriggerEnter2D(Collider2D other) // When touching a trigger object { if (other.CompareTag("Bullet")) // Check to see if the object is a bullet { if (!other.GetComponent <MoveBullet>().canGoThroughEnemies) // if bullet cannot go through enemies { Destroy(other.gameObject); // Destroy Bullet bulletCounter.DecreaseBulletAmount(); // Decrease bullet counter } TakeDamage(other.GetComponent <MoveBullet>().damage); spriteAnimator.ChangeAnimationState(TEST_OBJECT_HURT); // Play hurt animation } else if (other.CompareTag("PlayerMelee")) { // Take damage and add force TakeDamage(playerController.attackDamage); if (playerController.isFacingLeft) { playerDirection = -1; } else { playerDirection = 1; } Vector2 force = new Vector2(playerController.attackForce.x * playerDirection, playerController.attackForce.y); rb2d.AddForce(force + new Vector2(0.0f, -rb2d.velocity.y), ForceMode2D.Impulse); if (!playerController.isGrounded) { playerController.AirRebound(); // Call Air Rebound Function } spriteAnimator.ChangeAnimationState(TEST_OBJECT_HURT); // Play hurt animation } if (health <= 0) // if health is less than or equal to 0 { for (int i = 0; i < coins.Length; i++) { Instantiate(coins[i], transform.position, transform.rotation); } Destroy(gameObject); // Kill enemy } Invoke("ReturnToIdleAnimation", 0.1f); // reset to idle animation after hit }
private void Update() { currentClip = animator.GetCurrentAnimatorClipInfo(0); // Get info about the current clip if (EventSystem.current.currentSelectedGameObject == this.gameObject) // if this object is currently selected { spriteAnimator.ChangeAnimationState(selectAnimation); } else if (currentClip[0].clip.name != defaultState) // If the current clip is not the default state { spriteAnimator.ChangeAnimationState(deselectAnimation); } else { spriteAnimator.ChangeAnimationState(defaultState); } }
void PlayerDetected() { detectedPlayer = false; if (!droppedBomb) { spriteAnimator.ChangeAnimationState("FlyDropper_Dropped"); droppedBomb = true; Instantiate(bomb, transform.position, transform.rotation).GetComponent <FallingExplosive>().horizontalForce = rb2d.velocity.x / bombDropDivider; } Invoke("NextPhase", 1f); }
private void OnTriggerEnter2D(Collider2D other) // When touching a trigger object { if (other.CompareTag("Bullet")) // Check to see if the object is a bullet { health -= 10; // if it is a bullet, remove health [FIX: ADD BULLET SPECIFIC DAMAGE] spriteAnimator.ChangeAnimationState(TEST_OBJECT_HURT); // Play hurt animation } else if (other.CompareTag("PlayerMelee")) { if (playerController.isFacingLeft) { playerDirection = -1; } else { playerDirection = 1; } health -= 10; // if it is a bullet, remove health [FIX: ADD ATTACK SPECIFIC DAMAGE] Vector2 force = new Vector2(playerController.attackForce.x * playerDirection, playerController.attackForce.y); rb2d.AddForce(force + new Vector2(0.0f, -rb2d.velocity.y), ForceMode2D.Impulse); if (!playerController.isGrounded) { playerController.AirRebound(); // Call Air Rebound Function } spriteAnimator.ChangeAnimationState(TEST_OBJECT_HURT); // Play hurt animation } if (health <= 0) // if health is less than or equal to 0 { Destroy(gameObject); // Kill enemy } Invoke("ReturnToIdleAnimation", 0.1f); // reset to idle animation after hit }
private void InputAndResponse() // all things to do with pressing buttons and making the player react are here { // // Running // inputX = inputManager.inputX; if (Time.time >= nextWallJumpTime) { movement.x = inputX * moveSpeed; } else { movement.x = 0; } // // ANIMATIONS // if (AbleToUseAirAnimations()) { // animations for when in the air if (rb2d.velocity.y > 0) { spriteAnimator.ChangeAnimationState(PLAYER_JUMP); } else if (rb2d.velocity.y < 0) { spriteAnimator.ChangeAnimationState(PLAYER_FALL); } } else if (!isAttacking) { // If player is not shooting if (!isShooting) { if (movement.x != 0) // If player is moving { // Get the time of the animation and use it for the running & shooting animation AnimatorStateInfo runState = animator.GetCurrentAnimatorStateInfo(0); runTime = runState.normalizedTime % 1; spriteAnimator.ChangeAnimationState(PLAYER_RUN, runTime); } else { spriteAnimator.ChangeAnimationState(PLAYER_IDLE); runTime = 0; } } else // If player is shooting if (movement.x != 0) { // Get the time of the animation and use it for the run animation when we switch back to that AnimatorStateInfo runState = animator.GetCurrentAnimatorStateInfo(0); runTime = runState.normalizedTime % 1; spriteAnimator.ChangeAnimationState(PLAYER_RUN_SHOOT, runTime); } else { spriteAnimator.ChangeAnimationState(PLAYER_IDLE_SHOOT); runTime = 0; } } switch (movement.x) { case 0: rb2d.sharedMaterial = idleMaterial; // Make sure the player doesn't slide when idle break; default: rb2d.sharedMaterial = movingMaterial; // Remove friction from the player if (movement.x < 0) { playerSprite.flipX = true; // Flip the player sprite if moving left } else if (movement.x > 0) { playerSprite.flipX = false; // Keep the player facing right if otherwise } break; } if (rb2d.velocity.y < 0) { isRebounding = false; } // End Dash if (isHurt) { EndDash(); } else if (isGrounded && (inputManager.dashReleased || Time.time >= currentDashLength || dashStage == 0 || movement.x == 0)) { EndDash(); } }