Skip to main content

鼠标图片icon(选中物体变换图片)C#代码

using UnityEngine;
using System.Collections;

public class mouseicon : MonoBehaviour {

public Texture mouse_ico;
public Texture mouse_sweep; //鼠标经过
public Texture mouse_air; //鼠标点空气

void Start () {
Screen.showCursor=false;
}

// Update is called once per frame
void Update ()
{
mouse_ico=mouse_air;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray,out hit, 100))
{
Debug.DrawLine (ray.origin, hit.point);
if(hit.transform.tag=="enwu"
{
mouse_ico=mouse_sweep;
}
else
{
mouse_ico=mouse_air;
}
}
}
void OnGUI()
{
Vector3 mouse_pos= Input.mousePosition;
GUI.DrawTexture(new Rect(mouse_pos.x,Screen.height-mouse_pos.y,16,20),mouse_ico);
}
}