Okay so, My games dialogue box wont show on the window unless I drag it into the canvas, problem with that being is the dialogue box will show upon starting up the game when I hit play . How do I get this thing to only appear when the user presses the space bar down near the box?
Here’s a video of my problem so you can see first hand what I am dealing with
Keep the button in the canvas and disable it.
Add this script to a gameobject in the scene.
var yourButton : GameObject;
function Update (){
if(Input(GetKey(KeyCode.Space))
{
yourButton.SetActive (true);
}
}
Another good practice is to keep your game window to your desired build resolution/aspect ratio.
This makes it much easier to design and place your UI elements.
Take a look at anchoring UI elements.
https://docs.unity3d.com/Manual/UIBasicLayout.html
public class OpenDialog : MonoBehaviour
{
public GameObject boxDialogue;
public Transform player;
bool isActive;
public float someValue;
void Update()
{
if (Input.GetKey("space"))
{
float dist = Vector3.Distance(player.position, gameObject.transform.position);
if (!isActive && dist < someValue)
{
isActive = !isActive;
boxDialogue.SetActive(isActive);
}
else if(isActive)
{
isActive = !isActive;
boxDialogue.SetActive(isActive);
}
}
}
}
Attach that script to the box. Set the references on the inspector ,also set the someValue. It should work if i didn’t mess with the if conditions. There are other ways to check if it is close to the box that is up to you