Hey, I am making a game with a cannon that you can rotate to then shoot at cubes, Although when I change the rotation of the cannon, it just faces down and won’t even rotate when I press the buttons I created. Any help would be good, here is my code :
//var firePower : float;
var ball : Transform;
var ballPos : Transform;
var timer : float;
var addTime : boolean;
var theBall;
var move : boolean;
var rotationX : int = 270;
var barrel : Transform;
function Update(){
barrel.rotation.x = rotationX;
if(!addTime){
if(Input.GetKeyUp(KeyCode.Space)){
fire();
addTime = true;
}
}
if(move){
theBall.rigidbody.AddForce(-Vector3.forward * 50);
}
if(addTime){
timer += Time.deltaTime;
}
if(timer > 1){
addTime = false;
timer = 0;
theBall = GameObject.Find("Sphere(Clone)");
Destroy(theBall.gameObject);
}
}
function fire(){
Instantiate(ball,ballPos.position,ballPos.rotation);
move = true;
theBall = GameObject.Find("Sphere(Clone)");
}
function OnGUI(){
if(GUI.Button(Rect(10,10,100,30),"+")){
rotationX += 3;
}
if(GUI.Button(Rect(10,40,100,30),"-")){
rotationX -= 3;
}
}