Unity发布WebGL改变鼠标样式

记录:前段时间遇到一个需求,就是打包出来要在某种情况下鼠标的样子要改变成想要的样式。
详细代码如下

public Texture2D[] hand;//小指图标
    /// <summary>
    /// 鼠标变成小手图标的切换
    /// </summary>
    public void ChangeXiaoShou(bool isTrue)
    {
        IsEnter = isTrue;
        int index;
        index = Input.GetMouseButton(0) ? 0 : 1;
        if (isTrue)
        	Cursor.SetCursor(hand[index], Vector2.zero, CursorMode.Auto);//变成手
        else
            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);//变回来
    }

这样就可以实现了,但是后来打包web的时候发现还是没办法实现这个效果。目前只试了pc端可以这样弄。

web端的话,只需要把这个判断放在OnGUI里面就可以用了。

bool IsEnter;
    private void OnGUI()
    {
        if (IsEnter)
        {
            int index = Input.GetMouseButton(0) ? 0 : 1;
            GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 40, 40), hand[index]);
        }
    }

    public Texture2D[] hand;//小指图标
    /// <summary>
    /// 鼠标变成小手图标的切换
    /// </summary>
    public void ChangeXiaoShou(bool isTrue)
    {
        IsEnter = isTrue;
        int index;
        index = Input.GetMouseButton(0) ? 0 : 1;
        if (isTrue)
            Cursor.visible = false;//变成手
        else
            Cursor.visible = true;//变回来
    }

究其原因的话,我这边还是没找到是因为什么,个人感觉可能是没有权限吧。因为我的图标资源位置是随便放的。
如有不对,欢迎指正!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值