Death added

This commit is contained in:
2022-02-26 18:31:19 +03:00
parent 3ccc7a24b8
commit 5b9d219464
7 changed files with 283 additions and 8 deletions

View File

@@ -0,0 +1,19 @@
using Level;
using UnityEngine;
namespace Player
{
public class Death : MonoBehaviour
{
private AudioSource audioSource = null;
private void Start() => audioSource = GetComponent<AudioSource>();
public void Die()
{
LevelManager.Instance.CurrentLevel.Restart();
// Playing it after the restart because when the player gets deactivated the sound stops so it doesn't play the sound at all
audioSource.Play();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7c16e6ed26e877e42ba1955f39094ddf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,6 @@ using System;
using Movement;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using PlayerInput = Input.PlayerInput;
namespace Player
@@ -50,6 +49,8 @@ namespace Player
private const string IsGroundedParameter = "IsGrounded";
private const string IsWalledParameter = "IsWalled";
private Animator animator = null;
private Death death = null;
private CollisionChecker enemyTrigger = null;
private void Awake()
{
@@ -75,6 +76,8 @@ namespace Player
animator = GetComponent<Animator>();
audioSource = GetComponent<AudioSource>();
death = transform.Find("Death").gameObject.GetComponent<Death>();
enemyTrigger = GameObject.Find("Enemy Trigger").GetComponent<CollisionChecker>();
BaseSpeed = 0.0f;
}
@@ -133,12 +136,15 @@ namespace Player
{
_isOnAir = !_playerGroundTrigger.IsCollided;
RespawnCheck();
if (enemyTrigger.IsCollided)
death.Die();
}
private void RespawnCheck()
{
if (gameObject.transform.position.y < RespawnLimit)
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
death.Die();
}
// PAUSE METHODS