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

unity 鼠標(biāo)懸停事件操作

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

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

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

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

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

下面是完整

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
public class Shubiaoxuanting : MonoBehaviour{ 
    bool ischanger; //上移動(dòng) 0為未上移 1為上移 
    int move_up=0; 
    void Start () { ischanger = false; //擴(kuò)大碰撞體的尺寸 方便檢測(cè)鼠標(biāo)懸停             
       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); } 
        //鼠標(biāo)在物體上面引起的動(dòng)作 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"); 
     // // } 
     //鼠標(biāo)不再上面引起的動(dòng)作 
     void OnMouseExit(){ 
        ischanger = false; 
        this.transform.position = new Vector3 (this.transform.position.x, 0, this.transform.position.z); 
    }  /鼠標(biāo)按下
 
 /鼠標(biāo)按下 
void OnMouseDown(){  
 }
}
//鼠標(biāo)松開
//鼠標(biāo)松開
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);
// }}}

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

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

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

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

相關(guān)文章

最新評(píng)論

赤峰市| 宜州市| 珠海市| 襄垣县| 庆城县| 公主岭市| 惠州市| 彰化县| 惠来县| 富顺县| 鹤山市| 达拉特旗| 运城市| 略阳县| 兴义市| 郴州市| 确山县| 大宁县| 芒康县| 镇宁| 毕节市| 视频| 五河县| 泽普县| 衡水市| 朝阳市| 阳曲县| 建湖县| 晋江市| 南充市| 礼泉县| 贡觉县| 莱芜市| 巩留县| 宜良县| 大理市| 潞西市| 巴彦淖尔市| 恭城| 深州市| 安溪县|