- Home /
Duplicate Question
GUI SpaceShip Movement Problem!!! Please help!!
using UnityEngine;
using System.Collections;
public class simpleMovement : MonoBehaviour
{
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
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
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);
// 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);
rigidbody.AddRelativeForce(0,0,engineSpeed*speed*Time.deltaTime);
rigidbody.AddRelativeForce(strafe);
}
}
How do I use the GUI button press (already I have tried some ways, but am not able to achieve the effect) which is been assigned with respective texture to move the ship in yaw and pitch position. I have found the way to achieve this using keyboard controls, Please some one help me to fix this code for GUI texture. Thanks a lot, If you can please explain a bit, It would be of immense help. Thanks
Too much code with too little (none at all) explanation
Thanks. Sorry about the code it is with less explanation I understand. Am trying to just feed the input to a GUI button which is declared as public. The inputs are declared in axis declaration which is been commented on the code. Now I want that to be controlled with GUI texture. Thanks.
I believe you have it backwards. You do an if (GUI.Button) and if that's pressed you set moveLeft=True and in some other part of your script it sees moveLeft=true and it kicks in your movement code; you don't feed input to a GUI button, the button press feeds input to your other stuff.
Can you explain a bit with one example may be for one direction, literally am banging my head to understand this. :(
Answer by getyour411 · Sep 06, 2013 at 03:16 AM
You created two exact questions from the look of it, answered the other.
Sorry, for posting twice. Am not much familiar with this site. You can close this question. $$anonymous$$y mistake, apologize.
Follow this Question
Related Questions
Lerping the GUI, problem with doing it again 1 Answer
How do i repeat the Lerp movement? 1 Answer
Hit problem unity 1 Answer
Move back to starting point? 1 Answer