在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    unity3D下載要多少錢(unity3d下載)

      如何自定義消息?

      

      如果想自定義消息,是比較簡單的。在UnityEngine.EventSystems中有個名為‘IEventSystemHandler’的接口。從這接口的功能是通過消息傳遞系統(tǒng)接收事件的目標。我們來用一個彈跳案例來說明這個功能。

      首先是定義接口

      using UnityEngine;

      using System.Collections;

      using UnityEngine.EventSystems;

      public interface ICustomMessageTarget : IEventSystemHandler {

      void Jump();

      // void Message2();

      }

      一旦接口被定義了,就可以通過MonoBehaviour來使用這個接口。在這個例子中,當摁下鼠標左鍵時,會發(fā)送對應(yīng)的消息。定義的功能將被執(zhí)行。

      using UnityEngine;

      using System.Collections;

      using UnityEngine.EventSystems;

      public class NewBehaviour : MonoBehaviour {

      public GameObject mubiao;

      // Use this for initialization

      public void Update () {

      if(Input.GetMouseButtonDown(0)){

      ExecuteEvents.Execute(mubiao, null, MyEventF);

      }

      }

      public void MyEventF(ICustomMessageTarget handler, baseEventData eventData){

      handler.Jump ();

      }

      }

      消息發(fā)出后,需要一個目標也就是Cube來接收這個消息,當接收到消息之后,會執(zhí)行跳躍的命令。

      using UnityEngine;

      using System.Collections;

      //using UnityEngine.EventSystems;

      public class CustomMessageTarget : MonoBehaviour,ICustomMessageTarget {

      Rigidbody myRig;

      void Start(){

      myRig = this.GetComponent();

      }

      public void Jump(){

      myRig.velocity = Vector3.up*6;

      }

      }

      實例下載鏈接:http://pan.baidu.com/s/1hrxF9Ec 密碼:kwd1

      更多AR/VR資訊請關(guān)注微信:arinchina 網(wǎng)站:arinchina.com

    鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場,版權(quán)歸原作者所有,如有侵權(quán)請聯(lián)系管理員(admin#wlmqw.com)刪除。
    (0)
    用戶投稿
    上一篇 2023年7月12日 18:43
    下一篇 2023年7月13日 09:03

    相關(guān)推薦

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時間:周一至周五,10:30-18:30,節(jié)假日休息