Is there a code allowing me to add a custom mouse cursor for my game? If so, an example would be nice.
I use this one:
var originalCursor : Texture2D;
var cursorSizeX: int = 32; // set to width of your cursor texture
var cursorSizeY: int = 32; // set to height of your cursor texture
static var showOriginal : boolean = true;
function Start(){
Screen.showCursor = false;
//Screen.lockCursor = true;
}
function OnGUI(){
if(showOriginal == true){
GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX/2 + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY/2 + cursorSizeY/2, cursorSizeX, cursorSizeY),originalCursor);
}
}
See the code here.
Note these techniques have been rendered obsolete by Unity - Scripting API: Cursor.SetCursor
i use this C#(C sharp) script
using UnityEngine;
using System.Collections;
public class mousePointer : MonoBehaviour
{
public Texture2D cursorImage;
private int cursorWidth = 32;
private int cursorHeight = 32;
void Start()
{
Screen.showCursor = false;
}
void OnGUI()
{
GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursorImage);
}
}
You could also use the framework: http://edrivenunity.com/cursors
IT IS WORK IN CENTER OF CURSOR for you
var originalCursor : Texture2D;
var cursorSizeX: int = 128; // set to width of your cursor texture
var cursorSizeY: int = 58; // set to height of your cursor texture
static var showOriginal : boolean = true;
function Start(){
//Screen.showCursor = false;
//Screen.lockCursor = true;
}
function OnGUI(){
if(showOriginal == true){
GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX/2 + 1, (Screen.height-Input.mousePosition.y)-cursorSizeY/2 + 1, cursorSizeX, cursorSizeY),originalCursor);
}
}