- Home /
How can I change my mouse cursor every time I click?
I think my best bet would be with if statements and
Cursor.SetCursor
However it does not seem to work, I have tried with countless different combinations of code however they all seem to be failures.
For reference, my code is as follows, though ignore the commnts, they are there just incase I want to go back to a previous version of the code... The null which is included in the second if statement is just for Debugging/seeing if it actually works.
using UnityEngine;
using System.Collections;
public class mousePointer : MonoBehaviour
{
public Texture2D cursor;
//public Texture2D cursorTexture;
//public Texture2D cursorTextureClick;
private Vector2 hotSpot = Vector2.zero;
void Update()
{
if (Input.GetKeyDown (KeyCode.Space))
{
Cursor.SetCursor (cursor, hotSpot, CursorMode.Auto);
}
if (Input.GetMouseButtonDown (0))
{
Cursor.SetCursor(cursor2, Vector2.zero, CursorMode.Auto);
}
/* Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto);
if (Input.GetMouseButtonDown (0))
{
Cursor.SetCursor(cursorTextureClick, hotSpot, CursorMode.Auto);
}*/
}
// public Texture2D cursorImage;
// private int cursorWidth = 32;
// private int cursorHeight = 32;
// void Start()
// {
// Screen.showCursor = false;
// }
// void OnGUI()
// {
// if (Input.GetMouseButtonDown (0))
// {
// GUI.DrawTexture (new Rect (Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursorImage);
// }
// }
}
EDIT: I just wanted to note that I can get the first image working, aka the cursor the game will be using which I have created. However to do this the first if statement must be changed to just:
Cursor.SetCursor (cursor, hotSpot, CursorMode.Auto);
however this doesn't help as I still can't get it to change to a "null" cursor... :/
That is there just for test, what I want it do do is change cursor
Still no such thing as a null cursor. Use some other texture for it.
Answer by Arshia001 · Mar 30, 2015 at 12:00 PM
What's a null cursor anyway? If you want to hide the cursor, there's a different setting for it somewhere. Cursor.visible I think.
Your answer

Follow this Question
Related Questions
Unity 4.6: Convert GameObject into a UI.Button 2 Answers
How to use Button as Cross Platform Input 0 Answers
Add Cursor (Top-Down-Shooter) 1 Answer
Buttons in input manager don't do anything 1 Answer
Input button 0 Answers