using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseChange : MonoBehaviour
{
public Texture texture;//自己想要的鼠标图片
void Start()
{
Cursor.visible = false;
}
void OnGUI()
{
Vector3 vector3 = Input.mousePosition;
GUI.DrawTexture(new Rect(vector3.x - texture.width/2, (Screen.height - vector3.y) - texture.height/2, texture.width, texture.height), texture);
}
}
加入拖尾
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseChange : MonoBehaviour
{
public Texture texture;
public GameObject trail;//拖尾预制体
GameObject obj;
void Start ()
{
Cursor.visible = false;
obj = Instantiate(trail);//加载/克隆拖尾的预制体到场景
}
void OnGUI ()
{
Vector3 vector3 = Input.mousePosition;
GUI.DrawTexture(new Rect(vector3.x - texture.width/2, (Screen.height - vector3.y) - texture.height/2, texture.width, texture.height), texture);
//屏幕坐标转换到世界坐标
obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(obj.transform.position).z));
}
}