Death added
This commit is contained in:
@@ -6,7 +6,6 @@ namespace AI
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class Projectile : MonoBehaviour, IPausable
|
||||
{
|
||||
[SerializeField] protected float damageOnContact = 50f;
|
||||
private Rigidbody2D _rigidbody = null;
|
||||
|
||||
private void Awake()
|
||||
@@ -22,6 +21,9 @@ namespace AI
|
||||
private void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
ProjectilePool.Instance.Return(this);
|
||||
|
||||
if (other.transform.CompareTag("Player"))
|
||||
other.gameObject.GetComponent<Player.Death>().Die();
|
||||
}
|
||||
|
||||
public bool IsPaused { get; protected set; } = false;
|
||||
|
19
Assets/Scripts/Player/Death.cs
Normal file
19
Assets/Scripts/Player/Death.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Death.cs.meta
Normal file
11
Assets/Scripts/Player/Death.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c16e6ed26e877e42ba1955f39094ddf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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
|
||||
|
Reference in New Issue
Block a user