Hello everyone!! I need to modify my script to a Roll a Ball to use just one button to increase the speed of the ball. I make one script that have 4 buttons (one for each direction). I think it’s possible to use just one that can make the ball increase it’s speed in the direction it’s already going. This is the script i’m using:
#pragma strict
var directionxDir = Vector3(1, 0, 0);
var directionxEsq = Vector3(-1, 0, 0);
var directionzCim = Vector3(0, 0, 1);
var directionzBai = Vector3(0, 0, -1);
var posiX: float;
var posiY: float;
var altura: float;
var largura: float;
function Start () {
altura = 50;
largura = 50;
posiX = Screen.width/2 - largura/2 +25;
posiY = Screen.height/2 - altura/2 +100;
}
function Update () {
}
function OnGUI ()
{
if (GUI.Button(Rect(posiX-350,posiY+30,largura+15,altura),"Dash")){
rigidbody.AddForce (directionxDir * 1000);
}
if (GUI.Button(Rect(posiX-450,posiY+30,largura+15,altura),"Dash")){
rigidbody.AddForce (directionxEsq * 1000);
}
if (GUI.Button(Rect(posiX-400,posiY-25,largura+15,altura),"Dash")){
rigidbody.AddForce (directionzCim * 1000);
}
if (GUI.Button(Rect(posiX-400,posiY+85,largura+15,altura),"Dash")){
rigidbody.AddForce (directionzBai * 1000);
}
}
Thanks in advance