- Home /
Question by
Lonasora · Jul 01, 2017 at 03:52 PM ·
c#triggerif-statements
Cant get into the second if statment
when my character is on the trigger collider a canvas shows up on how to do something, and when the player press the in this situation the up arrowkey the character should do somthing. The first statement works, because the ui shows but when i press up arrowkey nothing happens. Thanks in advance :)
using UnityEngine;
using System.Collections;
public class cementary_move : MonoBehaviour
{
public bool onTrigger;
public GameObject Object_use;
public Canvas Canvas_use;
public Transform player;
private void Awake()
{
Canvas_use.enabled = false;
Canvas_use = Object_use.GetComponentInChildren<Canvas>();
}
void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.tag == "Player")
{
onTrigger = true;
Canvas_use.enabled = true;
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("test");
}
}
}
void OnTriggerExit(Collider coll)
{
if (coll.gameObject.tag == "Player")
{
onTrigger = false;
Canvas_use.enabled = false;
}
}
}
Comment
Best Answer
Answer by Kishotta · Jul 01, 2017 at 04:06 PM
OnTriggerEnter is only called on the frame that the collision occurs. You're probably wanting to put your KeyCode check in OnTriggerStay.