Files
beyond/Assets/Scripts/Triggers/ForceWalkTrigger.cs
2024-11-20 15:21:28 +01:00

66 lines
1.7 KiB
C#

using Invector.vCharacterController;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Beyond {
[RequireComponent(typeof(Collider))]
public class ForceWalkTrigger : MonoBehaviour
{
// Start is called before the first frame update
bThirdPersonInput m_vInput;
public bool m_fireOnce = true;
void Start()
{
var inputs = GameObject.FindObjectsOfType<bThirdPersonInput>();
if (inputs.Length == 0)
{
Debug.LogError("No melee input found!");
enabled = false;
return;
}
else if (inputs.Length > 1)
{
Debug.LogError("More then one melee input found!");
enabled = false;
return;
}
m_vInput = inputs[0];
gameObject.layer = LayerMask.NameToLayer("Triggers");
var collider = GetComponent<Collider>();
collider.isTrigger = true;
}
void ForceWalk(bool walk)
{
if (m_vInput!= null)
m_vInput.forceWalking = walk;
if (!walk && m_fireOnce)
Destroy(this);
}
private void OnDisable()
{
ForceWalk(false);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag != "Player")
return;
ForceWalk(true);
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag != "Player")
return;
m_vInput.forceWalking = false;
ForceWalk(false);
}
}
}