void Jump() { if (Input.GetKey(KeyCode.UpArrow) || (Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.Space)))) { if (grounded == true) { rb.velocity = new Vector2(rb.velocity.x, height); if (PlayerState == 0) { sfx.PlaySoundFX(defaultJumpSfx); } else { sfx.PlaySoundFX(bigJumpSfx); } } } if (jumping == true && jumped == true) { rb.gravityScale -= (.1f * Time.fixedDeltaTime); } if (jumpTime > 1f) { jumping = false; } if (jumping == false && jumped == true) { rb.gravityScale += .2f; } }
IEnumerator OnCollisionEnter2D(Collision2D other) { Vector3 impactPoint; impactPoint = other.contacts[0].point; bool isBelowBrick = impactPoint.y <= hitzone.min.y; if (CoinCount != 0 && isBelowBrick) { Object coin = Instantiate(CoinPrefab, spawnPoint.transform.position, spawnPoint.transform.rotation); yield return(new WaitForSeconds(.3f)); Debug.Log("sweet spot \t : " + impactPoint); sfx.PlaySoundFX(coinSfx); Destroy(coin); CoinCount--; ScoreManager.score += Coin.CoinValue; } if (CoinCount == 0) { // Play the famous bump sfx // Ensure that the blockFull status is correct // If the block is destroyed or not isBlockFull = false; print("You're breaking me... "); } }
IEnumerator OnCollisionEnter2D(Collision2D other) { Vector3 impactPoint; impactPoint = other.contacts[0].point; bool isBelowBrick = impactPoint.y <= hitzone.min.y; if (garbageCount != 0 && isBelowBrick) { Object garbage = Instantiate(garbagePrefab, spawnPoint.transform.position, spawnPoint.transform.rotation); yield return(new WaitForSeconds(.3f)); Debug.Log("sweet spot \t : " + impactPoint); sfx.PlaySoundFX(coinSfx); Destroy(garbage); garbageCount--; ScoreManager.score += BgarbageValue; PlayerController.GarbageNum += 1; } if (garbageCount == 0) { isBlockFull = false; print("You're breaking me... "); } }
//-------------------------------- void OnTriggerStay2D(Collider2D other) { //If not player then exit if (!other.CompareTag("Player")) { return; } //Damage player by rate PlayerController.Health -= Damage * Time.deltaTime; if (PlayerController.Health <= 0) { sfx.PlaySoundFX(DieSfx); } else { sfx.PlaySoundFX(damageSfx); } }
//-------------------------------- void OnTriggerEnter2D(Collider2D other) { //If not player entered, then exit if (!other.gameObject.CompareTag("Player")) { return; } //Lock player controls PlayerController.PlayerInstance.CanControl = false; sfx.PlaySoundFX(changeLevelSfx); SceneChange(); }
void FixedUpdate() { //If we cannot control character, then exit if (!CanControl || Health <= 0f) { return; } if (Input.GetKey(KeyCode.RightArrow) || (Input.GetKey(KeyCode.D))) { transform.Translate(Vector3.right * speed * Time.fixedDeltaTime); } if (Input.GetKey(KeyCode.LeftArrow) || (Input.GetKey(KeyCode.A))) { transform.Translate(Vector3.left * speed * Time.fixedDeltaTime); } if (jumped) { jumped = false; if (grounded == true) { //rb.velocity = new Vector2(0f, height); rb.velocity = new Vector2(rb.velocity.x, height); if (PlayerState == 0) { sfx.PlaySoundFX(defaultJumpSfx); } else { sfx.PlaySoundFX(bigJumpSfx); } } } }
void OnTriggerEnter2D() { if (isColliding) { return; } isColliding = true; if (PlayerController.GarbageNum >= 1) { Instantiate(Garbages, Spawn.transform.position, Quaternion.identity); ScoreManager.score += garbageDistinguishValue; sfx.PlaySoundFX(bigScoreSfx); } Destroy(this); print("Everybody puts once"); }