void Die() { Instantiate(playerDeath, transform.position, Quaternion.identity); Destroy(gameObject); FindObjectOfType <AudioManager>().Play("PlayerDeath"); shake.CamShake("ShakeBig"); }
void OnTriggerEnter2D(Collider2D collider) { cameraShake.CamShake(); Instantiate(explosionParticle, transform.position, Quaternion.identity); if (color == Color.red && collider.gameObject.name == "ShieldRed") { Destroy(gameObject); score.addScore(); gameManager.PlaySound(); } else if (color == Color.blue && collider.gameObject.name == "ShieldBlue") { Destroy(gameObject); score.addScore(); gameManager.PlaySound(); } else if (collider.gameObject.tag == "Projectile") { Destroy(gameObject); gameManager.PlaySound(); } else if (collider.gameObject.tag == "Player") { Destroy(collider.gameObject); dead.PlayerDead(); gameManager.PlaySound(); } }
void Die() { Instantiate(enemyDeath, transform.position, Quaternion.identity); Destroy(gameObject); FindObjectOfType <GameHandler>().finalScore += killPoints; FindObjectOfType <AudioManager>().Play("EnemyDeath"); shake.CamShake("ShakeSmall"); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("EnemyProjectile")) { shake.CamShake(); Debug.Log("You Have Been Hit!"); health -= 10; } }
public void TakeDamage(int damage) { if (isStaggered) { shake.CamShake(); enemyHealth -= damage; Instantiate(bloodeffect, transform.position, Quaternion.identity); } }
//Scala la vita del Player e la morte private void ProcessHit(DamageDealer damageDealer) { shake.CamShake(); AudioSource.PlayClipAtPoint(playerHitSound, Camera.main.transform.position, hitSoundVolume); health -= damageDealer.getDamage(); damageDealer.Hit(); if (health <= 0) { Die(); } }
//DAMAGE public void Damage() { _cameraShake.CamShake(); //if shields is active if (_isShieldsActive == true) { _shieldStrenth--; //Debug.Log("SHIELD STRENGTH: " + _shieldStrenth); if (_shieldStrenth == 2) { _shieldSpriteRenderer.color = new Color(0f, 1f, 0.3598187f, 1f); //Debug.Log(_shieldSpriteRenderer.color); } else if (_shieldStrenth == 1) { _shieldSpriteRenderer.color = new Color(1f, 0f, 0.7858334f, 1f); //Debug.Log(_shieldSpriteRenderer.color); } else if (_shieldStrenth == 0) { //deactivate shields _isShieldsActive = false; _shieldsVisualizer.SetActive(false); } return; } //Debug.Log("HIT"); //subtract 1 life _lives--; //update player animations UpdatePlayerAnimations(); //upate lives _uiManager.UpdateLives(_lives); //check if dead //destroy us if (_lives < 1) { //communicate with spawn manager //let them know to stop spawning _spawnManager.StopSpawning(); Instantiate(_explosionPrefab, transform.position, Quaternion.identity); Destroy(this.gameObject, 0.25f); } }
// Update is called once per frame void Update() { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset); if (Input.GetKeyDown(KeyCode.Mouse0)) { shake.CamShake(); Instantiate(laserProjectile, laserSpawn.position, laserSpawn.rotation); } }
//How to move camera and particles on impact public void Impact() { if (heavyAnimation) { shake.CamHeavyShake(); splashLandingHeavy.Play(); heavyAnimation = false; } else { shake.CamShake(); splashLanding.Play(); } }
// Update is called once per frame void Update() { //Player can only shoot while grounded (can't shoot while jumping) if (isGrounded) { //If player presses Left Click if (Input.GetKeyDown(KeyCode.Mouse0)) { //Spawn laser Instantiate(laser, laserSpawn.position, laserSpawn.rotation); //Access camera shake animation from CameraShake.cs script shake.CamShake(); //Play laser audio laserSFX.Play(); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Danger" && canDie == true) { canDie = false; shake.CamShake(); StartCoroutine(CharacterDeath()); } if (other.gameObject.tag == "Water" && canDie == true) { canDie = false; //shake.CamShake(); StartCoroutine(CharacterWaterDeath()); } if (other.gameObject.tag == "JumpBooster") { rb.velocity = new Vector2(0, 0); rb.AddForce(Vector2.up * 400); } if (other.gameObject.tag == "JumpBoosterDown") { rb.velocity = new Vector2(0, 0); rb.AddForce(Vector2.down * 400); } if (other.gameObject.tag == "JumpBoosterRight") { // rb.velocity = new Vector2(0, 0); //rb.AddForce(0, 200, 0); rb.velocity = new Vector2(0, -1); rb.AddRelativeForce(Vector2.right * 2000, ForceMode2D.Force); //rb.AddForce(Vector2.right * 2000, ForceMode2D.Force); Debug.Log("force"); //curSpeed = Speed; //rb.add } if (other.gameObject.tag == "JumpBoosterLeft") { // rb.velocity = new Vector2(0, 0); rb.AddForce(Vector2.left * 2000); } if (other.gameObject.tag == "Coin") { Destroy(other.gameObject); Coin++; PlayerPrefs.SetInt("Coin", Coin); //GameObject instance = (GameObject)Instantiate(coinPickupParticle, other.transform.position, Quaternion.identity); //Destroy(instance, 1.5f); } if (other.gameObject.tag == "LiftUp") { rb.velocity = new Vector2(0, 0); } if (other.gameObject.tag == "MoveRightZone") { crystalBase.GetComponent <CrystalController>().closeDoor = true; canControl = false; curSpeed = 2f; rb.velocity = new Vector2(curSpeed, rb.velocity.y); Debug.Log("MoveRightZone"); changeLevel = true; } if (other.gameObject.tag == "MoveLeftZone") { crystalBase.GetComponent <CrystalController>().closeDoor = true; canControl = false; curSpeed = -2f; rb.velocity = new Vector2(curSpeed, rb.velocity.y); Debug.Log("MoveRightZone"); changeLevel = true; } if (other.gameObject.tag == "StopMoveZone" && castOnce == false) { castOnce = true; crystalBase.GetComponent <CrystalController>().activeRedDoor = true; canControl = true; curSpeed = 0f; rb.velocity = new Vector2(0, rb.velocity.y); Debug.Log("StopMoveRightZone"); } //if (other.gameObject.tag == "CrushJump" && verticalVelocity < -3) //{ // Debug.Log("JumpCrush"); //} }
public static void Shake(float duration, float amount) { instance.StopAllCoroutines(); instance.StartCoroutine(instance.CamShake(duration, amount)); }
// Update is called once per frame void Update() { Vector2 directionalInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); SetDirectionalInput(directionalInput); CalculateVelocity(); HandleWallSliding(); controller.Move(velocity * Time.deltaTime, directionalInput); jumpPressedRemember -= Time.deltaTime; //direction detection if (directionalInput.x < 0) { transform.eulerAngles = new Vector3(0, 0, 0); isFacingRight = false; //ForCamera } else if (directionalInput.x > 0) { transform.eulerAngles = new Vector3(0, 0, 0); isFacingRight = true; //ForCamera } //Gravity + OnGround? if (controller.collisions.below) { isGrounded = true; velocity.y = 0; } else if (controller.collisions.above) { velocity.y = 0; } /* //HorizontalVelocity 'Acceleretion' if needed. * float fHorizontalVelocity = velocity.x; * fHorizontalVelocity += Input.GetAxisRaw("Horizontal"); * if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) < 0.01f) * { * fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenStopping, Time.deltaTime * 10f); * * } * else if (Mathf.Sign(Input.GetAxisRaw("Horizontal")) != Mathf.Sign(fHorizontalVelocity)) * { * fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenTurnning, Time.deltaTime * 10f); * } * else * { * fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingBasic, Time.deltaTime * 10f); * } * * velocity = new Vector2(fHorizontalVelocity, velocity.y); */ if (isGrounded) //Player is on the ground { isJumping = false; doubleJumped = false; canStomp = true; isStomped = false; if (Input.GetButtonDown("Jump")) { velocity.y = maxJumpVelocity; isJumping = true; isWallRunning = true; isGrounded = false; canDoubleJump = true; } } else //Player is in the air { jumpPressedRemember -= Time.deltaTime; if (Input.GetButtonUp("Jump")) //Half Jump { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; } } if (Input.GetButtonDown("Jump")) //Double jump { if (canDoubleJump) { if (!doubleJumped) { velocity.y = maxJumpVelocity; doubleJumped = true; canDoubleJump = false; } } if (canWallDoubleJump) //Need to fix walldoublejump issue { if (!wallDoubleJumped) { velocity.y = maxJumpVelocity; wallDoubleJumped = true; canWallDoubleJump = false; } } } if (Input.GetKeyDown(KeyCode.C)) // Air Stomp { if (canStomp) { velocity.y = stompSpeed * gravity; canStomp = false; isStomped = true; _shake.CamShake(); } } } }
void Update() { if (canMove) { Jumping(); WallJumping(); if (Input.GetKey(KeyCode.C) && onGround) { isSliding = true; } else if (!slideFirstFrame && isSliding == true && !Input.GetKey(KeyCode.C)) { isSliding = false; StopCoroutine(cameraShakeCam.CamShake(0, 0)); cameraShakeCam.transform.localPosition = cameraShakeCam.resetPos; /* if (isAlenvers) * { * cameraBase.transform.position = new Vector3(cameraBase.transform.position.x, cameraBase.transform.position.y - 1.5f, cameraBase.transform.position.z); * } * else * { * cameraBase.transform.position = new Vector3(cameraBase.transform.position.x, cameraBase.transform.position.y + 1.5f, cameraBase.transform.position.z); * Debug.Log("+from releasing c"); * } */ myCapsuleCollider5H.center = new Vector3(0, 2.5f, 0); myCapsuleCollider5H.height = 5; slideFirstFrame = true; } if (Input.GetKeyDown(KeyCode.R) || callDeath) { Death(); } } if (!isAlive) { Debug.Log(Time.time - justDied); } if (Time.time - justDied > 0.1f && !isAlive) { Debug.Log("Respawn"); source.PlayOneShot(spawnSound, 1.0f); transform.position = spawnPoint; fallStartingH = (int)transform.position.y; /* if (isAlenvers) * { * playerHolder.transform.position = this.transform.position; * transform.position = playerHolder.transform.position; * playerHolder.transform.eulerAngles = new Vector3(playerHolder.transform.rotation.x, playerHolder.transform.rotation.eulerAngles.y, -180); * isAlenvers = false; * } */ cameraBase.SetActive(true); timeLastDeath = Time.time; cam.mouseLook = new Vector2(checkpointDirection, 0f); justDied = 0f; isAlive = true; canMove = true; } //gravity control /* if (Input.GetKeyDown(KeyCode.E) && ChangeGravity == false || Input.GetButtonDown("Fire1") && ChangeGravity == false) * { * if ((fallStartingH - fallLandingH) < maxFallHeight) * { * fallStartingH = (int)transform.position.y; * } * if (isAlenvers == false) * { * Physics.gravity = new Vector3(0, reverseGravityValue, 0); * } else * { * Physics.gravity = new Vector3(0, -reverseGravityValue, 0); * } * StartCoroutine(GravityTimeController()); * ChangeGravity = true; * } */ if (Input.GetKeyDown(KeyCode.A) && !ChangeGravity && !isAlenvers && !powerIsOnCd && !isSliding) { Physics.gravity = new Vector3(0, -worldGravity, 0); isAlenvers = true; powerIsOnCd = true; playerHolder.transform.position = this.transform.position; transform.position = playerHolder.transform.position; playerHolder.transform.eulerAngles = new Vector3(playerHolder.transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, playerHolder.transform.rotation.eulerAngles.z); cam.mouseLook.x = 0; InitiateRotation(); } else if (Input.GetKeyDown(KeyCode.A) && !ChangeGravity && isAlenvers && !powerIsOnCd && !isSliding) { powerIsOnCd = true; isAlenvers = false; ResetGravity(); playerHolder.transform.position = this.transform.position; transform.position = playerHolder.transform.position; playerHolder.transform.eulerAngles = new Vector3(playerHolder.transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, playerHolder.transform.rotation.eulerAngles.z); cam.mouseLook.x = 0; InitiateRotation(); } }