Files
2026-02-21 16:45:37 +08:00

66 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class UIEvents : MonoBehaviour
{
public GameObject ball;
public Dropdown cmbScene;
public Text txtFPS;
public Text txtHelp;
[TextArea(3, 100)]
public string helpString;
public int cmbSelection;
private float deltaTime;
private void Start()
{
cmbScene.value = cmbSelection;
txtHelp.text = helpString;
cmbScene.onValueChanged.AddListener(delegate
{
cmbSelectionChanged(cmbScene);
});
ball = Object.Instantiate(ball, new Vector3(0f, -1000f, 0f), Quaternion.identity);
}
private void ThrowObject()
{
Vector3 position = Camera.main.transform.position;
ball.transform.position = position;
Debug.Log(position);
Vector3 forward = Camera.main.transform.forward;
ball.GetComponent<Rigidbody>().velocity = forward * 20f;
}
private void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
float num = deltaTime * 1000f;
float num2 = 1f / deltaTime;
string text = string.Format("{0:0.0} ms ({1:0000.} fps)", num, num2);
txtFPS.text = text;
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Space");
ThrowObject();
}
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(cmbScene.value);
}
}
private void cmbSelectionChanged(Dropdown target)
{
SceneManager.LoadScene(target.value);
Debug.Log(target.value);
}
}