最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

unity 鼠標懸停事件操作

 更新時間:2021年04月12日 09:47:21   作者:sogooday  
這篇文章主要介紹了unity 鼠標懸停事件操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

筆者在網(wǎng)上發(fā)現(xiàn)了,很多種方法 ,當然咱們找最好用的,也簡單的 下面廢話不多說直接上代碼 我在啰嗦幾句 第一這個腳本掛在需要相應(yīng)的游戲體上 第二被掛游戲體必須帶有collider, 第三僅僅制作完上面的兩步 本應(yīng)該沒有問題,

筆者又發(fā)現(xiàn)一個問題 就是只有鼠標在物體的右上方才會很靈敏的相應(yīng)到 在在左下方反而沒什么反應(yīng) ,為此筆者在腳本上加上了一句

this.GetComponent<BoxCollider> ().size = new Vector3 (1.5f, 1.5f, 1.5f);

原來物體的size 為(1,1,1) 我的目的是加大物體本身的碰撞體 結(jié)果順利的實現(xiàn)了

下面是完整

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
public class Shubiaoxuanting : MonoBehaviour{ 
    bool ischanger; //上移動 0為未上移 1為上移 
    int move_up=0; 
    void Start () { ischanger = false; //擴大碰撞體的尺寸 方便檢測鼠標懸停             
       this.GetComponent<BoxCollider> ().size = new Vector3 (1.5f, 1.5f, 1.5f); 
       //給麻將初始狀態(tài)的位置 this.transform.position = new Vector3         
       (this.transform.position.x, 0, this.transform.position.z); } 
        //鼠標在物體上面引起的動作 void OnMouseOver(){ ischanger = true;     
       this.transform.position = new Vector3 (this.transform.position.x, 0.2f, 
      this.transform.position.z); } 
     // void OnMouseEnter(){ 
     // ischanger = true; 
     // move_up = 1; 
     // Debug.Log ("3333333"); 
     // // } 
     //鼠標不再上面引起的動作 
     void OnMouseExit(){ 
        ischanger = false; 
        this.transform.position = new Vector3 (this.transform.position.x, 0, this.transform.position.z); 
    }  /鼠標按下
 
 /鼠標按下 
void OnMouseDown(){  
 }
}
//鼠標松開
//鼠標松開
void OnMousePut(){}
void OnMousePut(){}
void Update () {
// if (ischanger){
    //Debug.Log ("33333");
    //this.transform.position = new Vector3 (this.transform.position.x, 0.2f, this.transform.position.z)
} else {
// this.transform.position = new Vector3 (this.transform.position.x, 0, this.transform.position.z);
// }}}

補充:Unity UGUI Button鼠標的懸停事件(利用重寫unity中的button來實現(xiàn))

我就廢話不多說了,大家還是直接看代碼吧~

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
using UnityEngine.EventSystems; 
public class LearnButton : Button 
{ 
    /// 
    /// 配合Unity的其他方法使用,就能達到你想要的效果!這里只是拋磚引玉,大家有更好的方法歡迎跟我交流! 
    /// 
    /// 
    /// 
    protected override void DoStateTransition(SelectionState state, bool instant) 
    {
 
        base.DoStateTransition(state, instant); 
        switch (state) 
        {
 
            case SelectionState.Disabled: 
                break; 
            case SelectionState.Highlighted: 
                Debug.Log("鼠標移到button上!"); 
                break; 
            case SelectionState.Normal: 
                Debug.Log("鼠標離開Button!"); 
                break; 
            case SelectionState.Pressed: 
                break; 
            default: 
                break; 
        } 
    } 
}
 

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論

开鲁县| 呼玛县| 蒙城县| 海丰县| 房产| 孟连| 锡林郭勒盟| 图们市| 西青区| 嘉义市| 武宁县| 读书| 普陀区| 隆安县| 措勤县| 瑞丽市| 西乌珠穆沁旗| 宁化县| 泰来县| 淮安市| 铅山县| 巴马| 襄汾县| 乌什县| 沐川县| 收藏| 桑植县| 邵阳县| 中超| 昭平县| 乾安县| 霍城县| 龙山县| 措美县| 特克斯县| 新闻| 天水市| 通州市| 德昌县| 新沂市| 郴州市|