This code is meant to be a GUIButton with a jump function for the player which has a rigidbody. The GUIButton shows up but the jump function doesn’t respond. Can anyone point out any issues with this script?
This code is in JS(JavaScript/UnityScript)
var originalWidth = 1600.0; // define here the original resolution
var originalHeight = 900.0; // you used to create the GUI contents
var PositionX : float = 100;
var PositionY : float = 100;
var SizeX : float = 100;
var SizeY : float = 100;
var JumpSpeed: float = 100;
private var scale: Vector3;
function Jump () {
rigidbody.AddForce (Vector3.up *JumpSpeed);
}
function Update () {
if(GUI.Button(Rect(PositionX,PositionY,SizeX,SizeY), "Jump"))
Jump ();
}
function OnGUI () {
scale.x = Screen.width/originalWidth; // calculate hor scale
scale.y = Screen.height/originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
// substitute matrix - only scale is altered from standard
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
if(GUI.Button(Rect(PositionX,PositionY,SizeX,SizeY), "Jump"))
Jump ();
}
Thank You