Question by
Unity_GEAR · Feb 05 at 11:53 PM ·
inputprogramming
Why is my input not working everytime
My input only works sometimes when I press it. I think it might be that the input is not being registered every frame, but I am kinda new to programming, so I am having trouble trying to implement it. Here is my code, hopefully someone could help.
[System.Serializable]
public class NPC : MonoBehaviour { public Transform ChatBackGround; public Transform NPCCharacter;
private DialogueSystem dialogueSystem;
public string Name;
[TextArea(5, 10)]
public string[] sentences;
void Start()
{
dialogueSystem = FindObjectOfType<DialogueSystem>();
}
void Update()
{
Vector3 Pos = Camera.main.WorldToScreenPoint(NPCCharacter.position);
Pos.y += 175;
ChatBackGround.position = Pos;
}
public void OnTriggerStay(Collider other)
{
this.gameObject.GetComponent<NPC>().enabled = true;
FindObjectOfType<DialogueSystem>().EnterRangeOfNPC();
if ((other.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.F))
{
this.gameObject.GetComponent<NPC>().enabled = true;
dialogueSystem.Names = Name;
dialogueSystem.dialogueLines = sentences;
FindObjectOfType<DialogueSystem>().NPCName();
}
}
public void OnTriggerExit()
{
FindObjectOfType<DialogueSystem>().OutOfRange();
this.gameObject.GetComponent<NPC>().enabled = false;
}
}
Comment