- Home /
How would I make a math generator when I press space on a specified object?
I want my game to pop up an input field when the user presses space on an object, which in this case is a skeleton. I want it so the user can see a simple math question, and answer the question using the input field, but I have no idea where to start. I have the code that displays a dialog box when space is pressed but I don't have the input field popping up. Thank you in advance. ![alt text][1]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkeletonMath : MonoBehaviour {
public GameObject dialogBox;
public Text dialogText;
public string dialog;
public bool playerInRange;
public GameObject guess;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Space) && playerInRange)
{
if(dialogBox.activeInHierarchy)
{
Time.timeScale = 1f;
dialogBox.SetActive(false);
}else{
Time.timeScale = 0f;
dialogBox.SetActive(true);
dialogBox.text = dialog;
guess.SetActive(true);
}
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
//playerInRange = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
playerInRange = false;
dialogBox.SetActive(false);
}
}
}
Answer by tormentoarmagedoom · May 24, 2019 at 11:16 AM
Hello.
If you pretend to pop up different things at once, and all this things are in a Canvas, maybe best solution is to have the canvas with al elements ready, and just activate the whole canvas, or use the compoenent CanvasGroup to change transparency of all elements in the canvas togather.
If dont know how to proceed, go look for youtube tutorials about canvas, about input fields, etc..
Good luck!
Your answer
Follow this Question
Related Questions
How do I get this code to run specified amount of times 1 Answer
How to create a standard deviation number generator? 2 Answers
problem with mathf.tan 2 Answers
Need a little help with quick angle equation 2 Answers
CharacterController on Moving Surface 4 Answers