Hi, I’ve found a nice script here - http://www.joshuagamedev.com/on-screen-joystick-test/ and it’s throwing me an error that I can’t seem to fix Can anyone help?
Thanks in advance
// input variables public var baseTexture:Texture;// the base texture, usually the touchable area. public var joystickTexture:Texture ;// joystick texture, nothing but visual representation. public var touchArea:Rect;// the limits and size of touch action area. public var circleRadius:float;//joystick limit radius, it cannot move beyond this. public var invertY:boolean;// inverts the vertical output. //output variables | gives values from -1 to 1. static public var horizontal:float; static public var vertical:float; //calculation variables private var joystick:Rect; private var cursorPosition:Vector2;//x,y position of cursor/touch private var touchAreaCenter:Vector2;//stores the center of the touchable area. private var cursorDifference:Vector2;//the difference from cursor to center of touchable area. private var cursorDistance:float;//the distance from cursor and the center of touchable area. private var joystickPosition:Vector2;//position of the joystick. function Start() { // sets the touch area size to texture size if none is given. if ((touchArea.width || touchArea.height) == 0) { touchArea.width = baseTexture.width; touchArea.height = baseTexture.height; joystick.width = joystickTexture.width; joystick.height = joystickTexture.height; } touchArea.y = Screen.height - touchArea.height;// aligns the touchable area to bottom left. touchAreaCenter = Vector2(touchArea.x + touchArea.width / 2, touchArea.y + touchArea.height / 2); } function Update () { // screen space starts from bottom left. cursorPosition = ScreenToGUIPoint(Input.mousePosition);// converts screen space to GUI space. cursorDifference = cursorPosition - touchAreaCenter; cursorDistance = cursorDifference.magnitude; joystickPosition = Vector2(joystick.x, joystick.y); // if a touch is detected then execute else reset joystick to center of touch area if (Input.GetMouseButton(0) && touchArea.Contains(cursorPosition)) { // if the cursor is outside the circle radius, joystick is locked at the circle's circumference. if (cursorDistance circleRadius) { joystickPosition = touchAreaCenter + (cursorDifference / cursorDistance) * circleRadius; joystick.x = joystickPosition.x - joystick.width / 2; joystick.y = joystickPosition.y - joystick.height / 2; } else { joystickPosition = cursorPosition; joystick.x = cursorPosition.x - joystick.width / 2; joystick.y = cursorPosition.y - joystick.height / 2; } // converts the position of joystick(-1 to 1) using the circle circumference as limits and not the limits of toucharea. horizontal = Interpolate(joystickPosition.x, touchAreaCenter.x - circleRadius, touchAreaCenter.x + circleRadius, -1, 1); vertical = Interpolate(joystickPosition.y, touchAreaCenter.y + circleRadius, touchAreaCenter.y - circleRadius, invertY?1:-1, invertY?-1:1); } else { joystick.x = touchAreaCenter.x - joystick.width / 2; joystick.y = touchAreaCenter.y - joystick.width / 2; horizontal = vertical = 0; } } function OnGUI() { GUI.DrawTexture(touchArea, baseTexture, ScaleMode.ScaleAndCrop, true); GUI.DrawTexture(joystick, joystickTexture, ScaleMode.ScaleAndCrop, true); } function ScreenToGUIPoint(input:Vector2):Vector2 { return Vector2(input.x, Interpolate(input.y, Screen.height, 0, 0, Screen.height)); } private function Interpolate(xVar, xMin, xMax, yMin, yMax):float { return ( (xVar - xMin) / (xMax - xMin) ) * (yMax - yMin) + yMin; } **^ It's the last section here**
Assets/OnScreenJoystick.js
Operator ‘-’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘Object’.