我有一个空对象,其中包含下面的脚本。我要实现的是,如果敌人进入此触发框,则玩家无法做任何事情(他们被惊呆了)。直到他们按下“W”,敌人才会出现。我的setActive() false
问题是当我按下“W”时,即使敌人不再活跃在现场,角色也会长时间保持昏迷状态。我希望玩家按下“W”的那一刻,眩晕就完全消失并且不会持续很长时间。我还注意到,如果我按下“W”键,则需要一段时间才能进行确认,OnTriggerExit
然后才会注意到。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NoCasting : MonoBehaviour
{
[SerializeField]
private Image customImage;
//public Animator anim;
public Casting stop;
public AudioSource source;
public AudioSource negative;
public AudioSource helps;
public AudioSource positive;
public ParticleSystem stun;
// Use this for initialization
void Start ()
{
//anim = GetComponent<Animator> ();
source = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Enemy")
{
customImage.enabled = true;
Debug.Log ("is working trigger");
stop.GetComponent<Casting> ().enabled = false;
source.Play ();
negative.Play ();
stun.Play ();
//anim.Play ("DaniAttack");
}
}
private void OnTriggerExit(Collider other)
{
if (Input.GetKeyDown ("w"))
{
Debug.Log ("is ended trigger");
stun.Stop ();
negative.Stop ();
stop.GetComponent<Casting> ().enabled = !stop.enabled;
customImage.enabled = false;
helps.Play ();
positive.Play ();
}
}
}