Starter
This commit is contained in:
34
Assets/_Content/Scripts/Interactions/AmmoEffect.cs
Normal file
34
Assets/_Content/Scripts/Interactions/AmmoEffect.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using Arena.Characters;
|
||||
|
||||
namespace Arena.Interactions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gives ammo to the player. Apply is meant to be linked to a PlayerEvent.
|
||||
/// </summary>
|
||||
public class AmmoEffect : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Settings
|
||||
{
|
||||
[Tooltip("Ammo given to the player.")]
|
||||
[Min(1)] public int Amount = 10;
|
||||
}
|
||||
|
||||
#region FIELDS
|
||||
|
||||
[SerializeField] private Settings _settings;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
if (Player.Instance != null)
|
||||
Player.Instance.Launcher.AddAmmo(_settings.Amount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/Interactions/AmmoEffect.cs.meta
Normal file
2
Assets/_Content/Scripts/Interactions/AmmoEffect.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6739c594c812f4a4a84f51156853fc45
|
||||
34
Assets/_Content/Scripts/Interactions/HealEffect.cs
Normal file
34
Assets/_Content/Scripts/Interactions/HealEffect.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using Arena.Characters;
|
||||
|
||||
namespace Arena.Interactions
|
||||
{
|
||||
/// <summary>
|
||||
/// Heals the player. Apply is meant to be linked to a PlayerEvent.
|
||||
/// </summary>
|
||||
public class HealEffect : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Settings
|
||||
{
|
||||
[Tooltip("Health points given to the player.")]
|
||||
[Min(1)] public int Amount = 25;
|
||||
}
|
||||
|
||||
#region FIELDS
|
||||
|
||||
[SerializeField] private Settings _settings;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
if (Player.Instance != null)
|
||||
Player.Instance.Health.Heal(_settings.Amount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/Interactions/HealEffect.cs.meta
Normal file
2
Assets/_Content/Scripts/Interactions/HealEffect.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f7b07697ca242a4cbfd52a7158769ef
|
||||
90
Assets/_Content/Scripts/Interactions/PlayerEvent.cs
Normal file
90
Assets/_Content/Scripts/Interactions/PlayerEvent.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Arena.Characters;
|
||||
|
||||
namespace Arena.Interactions
|
||||
{
|
||||
public class PlayerEvent : MonoBehaviour
|
||||
{
|
||||
public enum Trigger
|
||||
{
|
||||
OnPlayerEnter,
|
||||
OnPlayerInteract
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Settings
|
||||
{
|
||||
[Tooltip("OnPlayerEnter: as soon as the player enters. OnPlayerInteract: when the player interacts inside the zone.")]
|
||||
public Trigger Trigger;
|
||||
}
|
||||
|
||||
[SerializeField] private Settings _settings;
|
||||
[SerializeField] private UnityEvent _onPlayer;
|
||||
|
||||
private bool _isListening;
|
||||
|
||||
#region UNITY LIFECYCLES
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// The object can be hidden while the player is inside
|
||||
StopListening();
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!IsPlayer(other))
|
||||
return;
|
||||
|
||||
if (_settings.Trigger == Trigger.OnPlayerEnter)
|
||||
_onPlayer.Invoke();
|
||||
else
|
||||
StartListening();
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (IsPlayer(other))
|
||||
StopListening();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool IsPlayer(Collider other)
|
||||
{
|
||||
return Player.Instance != null && other.gameObject == Player.Instance.gameObject;
|
||||
}
|
||||
|
||||
private void StartListening()
|
||||
{
|
||||
Player.Instance.OnInteract += HandleInteract;
|
||||
_isListening = true;
|
||||
}
|
||||
|
||||
private void StopListening()
|
||||
{
|
||||
if (!_isListening)
|
||||
return;
|
||||
|
||||
if (Player.Instance != null)
|
||||
Player.Instance.OnInteract -= HandleInteract;
|
||||
|
||||
_isListening = false;
|
||||
}
|
||||
|
||||
private void HandleInteract()
|
||||
{
|
||||
_onPlayer.Invoke();
|
||||
}
|
||||
|
||||
public void Teleport(Transform target)
|
||||
{
|
||||
if (!Player.Instance)
|
||||
return;
|
||||
|
||||
StopListening();
|
||||
Player.Instance.Teleport(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/Interactions/PlayerEvent.cs.meta
Normal file
2
Assets/_Content/Scripts/Interactions/PlayerEvent.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bed1a9cab72cda46bb8e8dd2d8c60a3
|
||||
Reference in New Issue
Block a user