MouseCursor > FlashPlayer

Hello.

I’ve correctly changed my game’s mouse cursor using this piece of code :

function OnGUI() {
var mousePos : Vector3 = Input.mousePosition;
var pos : Rect = Rect(mousePos.x,Screen.height - mousePos.y,cursorImage.width,cursorImage.height);
GUI.Label(pos,cursorImage);
}

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

This works fine when im in the editor and so on, but when i export to flash player, i always get the default mouse cursor (pointer) anyway.

How can i change the mouse cursor affecting the flashplayer export too ?

Thank you in advance.

You could hide the mouse cursor using ActionScript. Instead of having the line:

Screen.showCursor = false;

in your Start method, I would instead create a helper C# class to do this for you. You can then implement the same logic in ActionScript for the Flash export.

E.g.:

void Start()
{
    CursorHelper.Hide();
}

Then implement the CursorHelper C# class as follows. This C# implementation will be used in-editor and when you build to targets other than Flash:

using UnityEngine;

[NotConverted]
[NotRenamed]
public class CursorHelper 
{
	[NotRenamed]
	public static void Hide()
	{
		Screen.showCursor = false;
	}
}

Now make the same class in ActionScript (which will be used when you publish to Flash) and place it in a folder called “ActionScript” in your project:

package
{
	import flash.ui.Mouse;
	
	public class CursorHelper
	{
		public static function Hide() : void
		{
			Mouse.hide();
		}
	}
}

Here a script for you to try im not sure if it works because im at school(im 13)but im sure it will work for you

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);
    }


}