Merge remote-tracking branch 'origin/Syntriax' into Over
This commit is contained in:
@@ -6,22 +6,27 @@ namespace AI
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class Projectile : MonoBehaviour, IPausable
|
||||
{
|
||||
[SerializeField] protected float damageOnContact = 50f;
|
||||
private Rigidbody2D _rigidbody = null;
|
||||
public Rigidbody2D Rigidbody { get; private set; } = null;
|
||||
private AudioSource audioSource = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody2D>();
|
||||
Rigidbody = GetComponent<Rigidbody2D>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
public void SetVelocity(Vector2 velocity)
|
||||
{
|
||||
_rigidbody.velocity = velocity;
|
||||
Rigidbody.velocity = velocity;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
ProjectilePool.Instance.Return(this);
|
||||
audioSource.Play();
|
||||
|
||||
if (other.transform.CompareTag("Player"))
|
||||
other.gameObject.GetComponent<Player.Death>().Die();
|
||||
}
|
||||
|
||||
public bool IsPaused { get; protected set; } = false;
|
||||
@@ -39,7 +44,7 @@ namespace AI
|
||||
|
||||
private void UpdateRigidbody()
|
||||
{
|
||||
_rigidbody.simulated = !IsPaused;
|
||||
Rigidbody.simulated = !IsPaused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,14 +42,16 @@ namespace AI
|
||||
if (projectile == null)
|
||||
projectile = Instantiate(prefab).GetComponent<Projectile>();
|
||||
|
||||
projectile.gameObject.SetActive(true);
|
||||
projectile.transform.position = Vector3.left * 10000;
|
||||
projectile.Rigidbody.simulated = true;
|
||||
|
||||
return projectile;
|
||||
}
|
||||
|
||||
public void Return(Projectile projectile)
|
||||
{
|
||||
projectile.gameObject.SetActive(false);
|
||||
projectile.Rigidbody.simulated = false;
|
||||
projectile.transform.position = Vector3.right * 10000;
|
||||
pool.Push(projectile);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ namespace AI
|
||||
protected bool isShooting = false;
|
||||
protected IMovement movement = null;
|
||||
protected Animator animator = null;
|
||||
protected AudioSource audioSource = null;
|
||||
protected int layerMask = ~(1 << 9);
|
||||
|
||||
protected bool canShoot => target != null && (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared;
|
||||
@@ -44,6 +45,7 @@ namespace AI
|
||||
{
|
||||
movement = transform.GetComponentInParent<IMovement>();
|
||||
animator = transform.GetComponentInParent<Animator>();
|
||||
audioSource = transform.GetComponentInParent<AudioSource>();
|
||||
UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
|
||||
}
|
||||
|
||||
@@ -90,6 +92,7 @@ namespace AI
|
||||
projectile.SetVelocity(velocity);
|
||||
|
||||
remainingCooldown = cooldownPerShoot;
|
||||
audioSource.Play();
|
||||
OnShoot?.Invoke();
|
||||
}
|
||||
|
||||
|
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
|
||||
@@ -28,6 +27,7 @@ namespace Player
|
||||
private PlayerInput _controls;
|
||||
private Rigidbody2D _playerRigidbody2D;
|
||||
private SpriteRenderer _playerSpriteRenderer;
|
||||
private AudioSource audioSource = null;
|
||||
|
||||
private CollisionChecker _playerGroundTrigger;
|
||||
private CollisionChecker _playerWallTriggerLeft;
|
||||
@@ -47,7 +47,10 @@ namespace Player
|
||||
|
||||
private const string IsMovingParameter = "IsMoving";
|
||||
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()
|
||||
{
|
||||
@@ -72,6 +75,9 @@ namespace Player
|
||||
_canJump = true;
|
||||
|
||||
animator = GetComponent<Animator>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
death = transform.Find("Death").gameObject.GetComponent<Death>();
|
||||
enemyTrigger = GameObject.Find("Enemy Trigger").GetComponent<CollisionChecker>();
|
||||
|
||||
BaseSpeed = 0.0f;
|
||||
}
|
||||
@@ -115,7 +121,9 @@ namespace Player
|
||||
_playerRigidbody2D.velocity = new Vector2(0.0f, _playerRigidbody2D.velocity.y);
|
||||
animator.SetBool(IsMovingParameter, false);
|
||||
}
|
||||
|
||||
animator.SetBool(IsGroundedParameter, _playerGroundTrigger.IsCollided);
|
||||
animator.SetBool(IsWalledParameter, _playerWallTriggerLeft.IsCollided || _playerWallTriggerRight.IsCollided);
|
||||
|
||||
if (_jumpKeyPressed && _playerGroundTrigger.IsCollided && _canJump)
|
||||
Jump();
|
||||
@@ -128,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
|
||||
@@ -217,6 +228,7 @@ namespace Player
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
audioSource.Play();
|
||||
BaseSpeed = MaxAirSpeed;
|
||||
_playerRigidbody2D.velocity = new Vector2(_playerRigidbody2D.velocity.x, DefaultJumpForce);
|
||||
_canJump = false;
|
||||
|
Reference in New Issue
Block a user