RTS Cursors

Hi,

I am having a problem with the Unity Cursors, heres the code I have below. The problem is it does not update in my game unless I click off of the game, say click on the scene window, and then click back. I read somewhere on the manual that it updates only when its moving?

void Update()
	{

		Cursors();
}


...

void Cursors()
	{
		if(selectedObject != false)
		{
			Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto);
		}
		else 
		{
			Cursor.SetCursor(null, hotSpot, CursorMode.Auto);
		}
	}

...

The idea is that I eventually have all my cursor requirements in this one function such as move, attack, default etc. Is this a valid way or can I make use of the new UI?? Am I better to just script a texture to follow the mouse position?

Cheers,
Steve.

Just script a Texture(Or an Image if you want to use the new UI functions) to follow the mouse position. It’s what I use when I need to make a custom cursor, and it hasn’t failed me yet. With the new UI system you can have one Image like CurrentImage.SetActive(False) and another DifferentImage.SetActive(True) anytime you want the cursor to change for attack, default, move, etc.

Here is the final script, at first I implemented SnStarr’s answer but turning the objects on and off was producing a slight flicker as each object adjusted its position (because the follow script is on each object). In the end I just attached the images and used.enable = false/true.

Code as follows…

Cursor Follow

using UnityEngine;
using System.Collections;

public class FollowMouse : MonoBehaviour {

	
	// Update is called once per frame
	void Update () {

		transform.position = Input.mousePosition;
	
	}
}

Mouse Code

//CURSORS
	public Image moveCursor;
	public Image attackCursor;
	public Image defaultCursor;



	void Awake()
	{

		moveCursor = GameObject.Find("MoveCursor").GetComponent<Image>();
		attackCursor = GameObject.Find("AttackCursor").GetComponent<Image>();
		defaultCursor = GameObject.Find("DefaultCursor").GetComponent<Image>();
	}

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

		Cursors();
...
...
...

}

	void Cursors()
	{

		if(selectedObject != false)
		{
			

			defaultCursor.enabled = false;
			attackCursor.enabled = false;
			moveCursor.enabled = true;
		}
		else
		{


			defaultCursor.enabled = true;
			attackCursor.enabled = false;
			moveCursor.enabled = false;
		}
	}