Answer the question
In order to leave comments, you need to log in
ui button as a button on the keyboard. What to do?
unity. csharp. Wrote a simple script under the clave:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Door : MonoBehaviour {
public KeyCode aktion = KeyCode.E;
public int level;
public bool InTrigger = true;
public GameObject door;
public void Start ()
{
}
public void Update ()
{
}
public void pressA ()
{
Input.GetKey (aktion);
print ("eee");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player") {
InTrigger = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Player") {
InTrigger = !InTrigger;
}
}
public void FixedUpdate ()
{
if (Input.GetKey (aktion) && InTrigger) // действие, если на триггере и нажата клавиша
{
SceneManager.LoadScene (level); // переход
}
}
}
Answer the question
In order to leave comments, you need to log in
UI Button has Events. It is possible through the inspector, it is possible with code ( https://docs.unity3d.com/ScriptReference/UI.Button...
I'm a little surprised how people can not find / skip) this important tutorial)
https://unity3d.com/en/learn/tutorials/topics/user...
and the code option is excellent as GavriKos tells you.
code in practice is sometimes even better if you do not have a simple menu that is easy to remember anyway.
it will be easier to find links and where is it called and from where)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question