{
public float speed = 0.00f;
public float rotSpeed = 10.0f;
public float strafeSpeed =10.0f;
private float engineSpeed = 0.0f;
public float pitchConstant = 1.0f;
public float yawConstant = 0.0f;
public GameObject boostersprefab;
public GameObject boosterPos;
private GameObject instantiated;
private bool instanBoostersExist;
// GUI texture
public GUITexture forwardPitchButton;
public GUITexture backwardPitchButton;
public GUITexture leftPitchButton;
public GUITexture rightPitchButton;
// Booster Start Function (Instantiate the particles)
void boostersStart()
{
if(instanBoostersExist == false)
{
instantiated = (GameObject)Instantiate(boostersprefab, boosterPos.transform.position, boosterPos.transform.rotation);
instantiated.transform.parent = boosterPos.transform;
instanBoostersExist = true;
}
}
// Booster Stop Function (Stop Instantiating the particles)
void boosterStop()
{
if (instanBoostersExist == true)
{
Destroy(instantiated,0.2f);
instanBoostersExist = false;
}
}
void Update()
{
// Axis Declaration
float pitch = Input.GetAxis("Pitch")*pitchConstant;
float yaw = Input.GetAxis ("Yaw")*yawConstant;
float roll = Input.GetAxis ("Roll");
float gas = Input.GetAxis ("Gas");
Vector3 strafe = new Vector3 (Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime,Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime,0);// Vertical and Horizontal Axis is feeded to the strafe movement.
// Engine Mechanism
if (engineSpeed <10 && engineSpeed > -3)
{
engineSpeed += gas;
boostersStart();
}
if(engineSpeed > 10)
{
engineSpeed = (9.99f);
}
if (engineSpeed<-3)
{
engineSpeed = (-2.99f);
}
else if(Input.GetKey("z"))// Brake
{
engineSpeed = (0.00f);
boosterStop();
}
// SpaceShip Physics Movement
rigidbody.AddRelativeTorque(pitch*rotSpeed*Time.deltaTime,yaw*rotSpeed*Time.deltaTime,roll*rotSpeed*Time.deltaTime); // realative torque is added
rigidbody.AddRelativeForce(0,0,engineSpeed*speed*Time.deltaTime); // relative force
rigidbody.AddRelativeForce(strafe); // rigidbody added to the strafe movement
}
}
How do I feed the movement function to GUI button?, I already created GUI texture and declared it int he program. I tried many way but couldn’t get it working. i just want to move the ship when the GUI button is pressed instead of keyboard controls. Please help me out. Thanks a lot.