1.隱藏鼠標(biāo)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson2 : MonoBehaviour
{
void Start()
{
//true:顯示
//false:隱藏
Cursor.visible = false;
}
}
2.鎖定鼠標(biāo)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;、
public class Lesson2 : MonoBehaviour
{
void Start()
{
//None:不鎖定 解除鎖定
//Locked:鎖定,鼠標(biāo)會(huì)被鎖定在屏幕的中心點(diǎn)(并且會(huì)被隱藏)
//Confined:將鼠標(biāo)限制在窗口范圍內(nèi)
Cursor.lockState = CursorLockMode.Locked;
}
}
3.設(shè)置鼠標(biāo)圖片
把導(dǎo)入的光標(biāo)圖片資源設(shè)置成Cursor類型
注意:想要圖片不變形,要使用寬高一樣的圖片文章來源地址http://www.zghlxwxcb.cn/news/detail-511363.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson2 : MonoBehaviour
{
//外部拖拽光標(biāo)圖片
public Texture2D tex;
void Start()
{
//參數(shù)1 光標(biāo)圖片 外部拖拽的
//參數(shù)2 偏移位置 相對(duì)圖片左上角
//參數(shù)3 平臺(tái)支持的光標(biāo)模式(硬件或軟件)一般用Auto自動(dòng)模式即可
Cursor.SetCursor(tex, Vector2.zero, CursorMode.Auto);
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-511363.html
到了這里,關(guān)于【Unity】Cursor類——隱藏鼠標(biāo)、鎖定鼠標(biāo)、設(shè)置鼠標(biāo)圖標(biāo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!