- Home /
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.
Answer by catburton · May 30, 2012 at 03:54 PM
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();
}
}
}
Thank you very much, Your code worked like a charm, and better, i understanded very well how to integrate AS with Unity - a thing that i was lookinng forward for something like 2 weeks :S
Thank so much for the solution , and for the "lesson" :)
Answer by BigBlob · May 29, 2012 at 03:58 PM
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);
}
}
Hello.
Thank you for your answer. I tryed your code but i get the same problem. $$anonymous$$aybe i havent explained the problem good enough ... when i export to flash, my mouse cursor gets the texture i want, but on top of the texture i have the normal browser arrow ... i mean, my mouse cursor on the flash player is the Operative System cursor pointer plus the texture :S
Your answer