我想知道如何通過觸摸來做某事。請寫任何腳本示例或做什么。
public Transform MoveThis;
public GameObject Here;
void OnClick() => MoveThis.transform.position = Here.transform.position;
我看了很多 youtube 視頻,嘗試了很多腳本,但似乎都不適合我。
uj5u.com熱心網友回復:
Unity 檔案是知識的源泉,包括IPointerClick 界面的頁面。
在那個頁面上有一個小例子:
using UnityEngine;
using UnityEngine.EventSystems;
public class Example : MonoBehaviour, IPointerClickHandler
{
//Detect if a click occurs
public void OnPointerClick(PointerEventData pointerEventData)
{
//Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject.
Debug.Log(name " Game Object Clicked!");
}
}
需要特別注意的一件事是這條指令:
確保場景中存在事件系統以允許點擊檢測。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534978.html
標籤:unity3d按钮移动的
