Hi. Thank you for your time.
So I want to switch between two different cursors depending on the tag the cursor hovers over. My own script just won’t do the trick for some reason. Can someone help me out, please?
using UnityEngine;
using System.Collections;
public class Cursor : MonoBehaviour {
public Texture cursorTextureNormal;
public Texture cursorTextureNo;
private bool opTag = false;
private Ray ray;
private RaycastHit;
void Start()
{
Screen.showCursor = false;
}
void OnGUI()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 mousePos = Input.mousePosition;
if(Physics.Raycast(ray, out hit))
{
if(hit.collider.gameObject.tag == "grond")
{
opTag = true;
}
if(opTag = true)
{
Rect pos = new Rect(mousePos.x, Screen.height - mousePos.y, cursorTextureNormal.width, cursorTextureNormal.height);
GUI.Label(pos, cursorTextureNormal);
}
else{
Rect pis = new Rect(mousePos.x, Screen.height - mousePos.y, cursorTextureNo.width, cursorTextureNo.height);
GUI.Label(pis, cursorTextureNo);
}
}
}
}
}