- Home /
Box Collider 2D is not consitently working
I made a dialogue system in a 2D rpg. When the player is in the dialogue Zone (Box Collider 2D) he should be able to press F to accses a dialogue. However it only works about every fifth time. I used a tutorial on youtube https://www.youtube.com/watch?v=BrCxFpZFRS0&list=PLiyfvmtjWC_X6e0EYLPczO9tNCkm2dzkm∈dex=29&t=0s . I've already tried to add the never Sleep thing but it didn't work. Code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DialogueHolder : MonoBehaviour { public string dialogue; private DialogueManager dMan;
public string[] dialogueLines;
// Start is called before the first frame update
void Start()
{
dMan = FindObjectOfType<DialogueManager>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerStay2D(Collider2D other)
{
if (other.gameObject.name == "player")
{
if (Input.GetKeyUp(KeyCode.F))
{
//dMan.ShowBox(dialogue);
if (!dMan.dialogActive)
{
dMan.dialogLines = dialogueLines;
dMan.currentLine = 0;
dMan.ShowDialogue();
}
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612225625im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Jumping from Obstacle while adding velocity to Player 0 Answers
Screen scaling causing text to be outside button 0 Answers
Second Coroutine isn't working Unity 1 Answer
How can i save a variable for only one scene? 1 Answer
How can I made a In app Purchase code (google play store) for unity 2019.1.9 ? 0 Answers