/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Demo
{
using Opsive.UltimateCharacterController.Character;
using UnityEngine;
///
/// Disables the specified Collider when the character enters the trigger.
///
public class ColliderDisabler : MonoBehaviour
{
[Tooltip("The Collider that should be disabled.")]
[SerializeField] protected Collider m_DisableCollider;
private DemoManager m_DemoManager;
///
/// Initialize the default values.
///
private void Awake()
{
m_DemoManager = FindObjectOfType();
}
///
/// An object has entered the trigger.
///
/// The object that entered the trigger.
private void OnTriggerEnter(Collider other)
{
var characterLocomotion = other.GetComponentInParent();
if (characterLocomotion == null) {
return;
}
if (characterLocomotion.gameObject != m_DemoManager.Character) {
return;
}
m_DisableCollider.enabled = false;
}
///
/// An object has left the trigger.
///
/// The object that exited the trigger.
private void OnTriggerExit(Collider other)
{
var characterLocomotion = other.GetComponentInParent();
if (characterLocomotion == null) {
return;
}
if (characterLocomotion.gameObject != m_DemoManager.Character) {
return;
}
m_DisableCollider.enabled = true;
}
}
}