- Home /
On screen button forward for a car (Android)
So it's like this. I'm trying to develop a sandbox, free roam, whatever app where you will drive a car. I got the car physics, model and everything, but now I'm trying to put on screen controls like going forward, reverse, left and right. I have been reading all night now, input controls and stuff and I'm still breaking my head over it. I'm pretty much to JavaScript and all programming language, so any help would be useful.
Something that I came up with:
if (GUI.Button(Rect(10,10,10,10),"Forward")){
FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical") * speed;
FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical") * speed;
}
I don't know why the rectangle wouldn't show up. How can I pull this off?
Thanks!
Answer by The_Magical_Kiwi · Jun 27, 2012 at 09:09 AM
The button size (10,10) is tiny. You can see a (10,10) button in the top corner of this 1024x768 screenie.
Try making it bigger, that will make it easier to spot. Also if you are using a gui skin, check to see if you haven't accidently set the button alpha value all the way down and made it transparent.
Make sure that the button code is inside an OnGUI function in your script:
void OnGui{
if (GUI.Button(Rect(10,10,10,10),"Forward")){
//do something
}
}
If you are using c# that will need to read:
if (GUI.Button(new Rect(10,10,10,10),"Forward")){
Hope that helps.
this code is inside function Update() and i still havent managed how to do it.
Your answer
Follow this Question
Related Questions
Android H/w Camera Button 1 Answer
Collision not working. 1 Answer
Android Dualshock Controller Button Mapping Issue 0 Answers
Using your Android as a controller for your Unity PC Game 1 Answer
Joystick Sideways Movement 0 Answers