Unity 2d/3d 拖拽
阿新 • • 發佈:2019-01-23
using System.Collections; using System.Collections.Generic; using UnityEngine; //介面引用的事件系統名稱空間 using UnityEngine.EventSystems; public class Test_2d : MonoBehaviour, IDragHandler,IPointerClickHandler { private bool stop; private bool animation_demo; private bool dong; Vector3 v1; Quaternion q1; // Use this for initialization void Start () { v1 = transform.position; q1 = transform.rotation; } // Update is called once per frame void Update () { if (dong == true) { transform.position = Vector3.MoveTowards(transform.position,v1, 2 ); transform.rotation = Quaternion.Lerp(transform.rotation, q1, 2 ); } } //3d 可用 private void OnMouseOver() { print("over_3"); } //3d 可用 private void OnMouseDown() { print("down_3"); } //3d 可用 private void OnMouseDrag() { print("drag_3"); } public void OnDrag(PointerEventData eventData) { print("drag_2"); if (animation_demo == false) { transform.position = Input.mousePosition; } } public void OnPointerClick(PointerEventData eventData) { print("Click_2"); } //2d 3d均可 private void OnTriggerEnter(Collider other) { print(other.name); if (other.name == "Button") { animation_demo = true; transform.GetComponent<Collider>().enabled = false; StartCoroutine(Yanshi()); if (stop == false) { transform.GetComponent<Animation>().CrossFade("one"); } else { transform.GetComponent<Animation>().CrossFade("two"); } stop = !stop; } } IEnumerator Yanshi() { yield return new WaitForSeconds(1.5f); dong = true; yield return new WaitForSeconds(2); dong = false; transform.GetComponent<Collider>().enabled = true; animation_demo = false; } }
G
M
T
中文簡體日語英語 | 中文簡體日語英語 |
文字轉語音功能僅限200個字元
選項 : 歷史 : 反饋 : Donate | 關閉 |