Hello everyone!
I am trying to change this script that turns the mouse cursor to 360 degrees. I added a boxcollider2d so that activates when the mouse wheel position 180 °. Unfortunately this does not happen, the boxcollider remains active when I start the game.
Any solution?
script:
#pragma strict
var yourCursor : Texture2D; // Your cursor texture
var cursorSizeX : int = 16; // Your cursor size x
var cursorSizeY : int = 16; // Your cursor size y
var speed = 90.0;
private var angle = 0.0;
var box : GameObject;
function Start()
{
Screen.showCursor = false;
box.GetComponent(BoxCollider2D).enabled = false;
}
function Update()
{
{
if (Input.GetMouseButton (0))
angle -= Time.deltaTime * speed;
angle = angle % 360.0;
box.GetComponent(BoxCollider2D).enabled = true;
Screen.showCursor = false;
}
{
if (Input.GetMouseButton (1))
angle += Time.deltaTime * speed;
angle = angle % 360.0;
box.GetComponent(BoxCollider2D).enabled = true;
Screen.showCursor = false;
}
}
function OnGUI()
{
var matx = GUI.matrix;
var x = Event.current.mousePosition.x-cursorSizeX/2.0;
var y = Event.current.mousePosition.y-cursorSizeY/2.0;
var pivot = Vector2(x + cursorSizeX / 2.0,y + cursorSizeY / 2.0);
GUIUtility.RotateAroundPivot(angle, pivot);
GUI.DrawTexture (Rect(x, y, cursorSizeX, cursorSizeY), yourCursor);
GUI.matrix = matx;
}
Script Solution:
function Update()
{
{
if (Input.GetMouseButton (0))
angle -= Time.deltaTime * speed;
angle = angle % 180.0;
box.GetComponent(BoxCollider2D).enabled = true;
Screen.showCursor = false;
}
{
if (Input.GetMouseButton (1))
angle += Time.deltaTime * speed;
angle = angle % 180.0;
box.GetComponent(BoxCollider2D).enabled = true;
Screen.showCursor = false;
}
}