|
i have a script to control my airplan and i want to make it work with the iphone so i want to use gui buttons to accelerate i have the accelerationg script here how do i make it work with gui buttons
(comments are locked)
|
|
Check here for information about GUI Buttons Following code is in C#, not JavaScript! Look at the link for JavaScript examples. Basically you need a OnGui function which is like an update function but is specifically used to handle GUI elements in a 2D environment. GUI Elements will always render on top of scene elements. When creating a button, you need to setup the x and y position, and the width and height of the button. When creating a button, you can do tricks like scaling it to a portion of the screen size so that it will always be a particular size to the screen, useful for porting to multiple devices who have different screen size. Example: Heres some example code to get you started (Untested code in C#, check the link for a javascript version): Optimising your code a little, this is for acceleration. Write another "if(GUI.Button" for deceleration. Leave a comment and tell me if you're having trouble or if my answer didn't suit your needs. how do i make it on tap because i want this to work on the iphone
Dec 25 '11 at 08:25 AM
cubelord
and it gives me a few errors like expression denotes a value where a method is expected here is the final code using UnityEngine; using System.Collections; public class accelerate : MonoBehaviour { { if(GUI.Button(new Rect(10, 10, 50, 50),"Accelerate")) { if ((groundtrigger.triggered == 1) (Input.GetButton ("Fire1 "))&&( speed <800)) + speed = Time.deltaTime * 240; else if ((groundtrigger.triggered == 0) (Input.GetButton ("Fire1 "))&&( speed <800)) + speed = Time.deltaTime * 240; } } }
Dec 25 '11 at 09:04 AM
cubelord
Unity codes GUI.Button to work for touches, but without using the code for handling multiple touches I think that won't work. You can check for multi-touch with this method (There are probably other ways but this is easiest): Rect buttonArea = new Rect(10,10,100,50); foreach ( Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began && buttonArea.Contains(touch.position)) { //Do stuff } } I copy pasted the code directly from your question, try changing the if statements to this: if ((groundtrigger.triggered == 1) (Input.GetButton ("Fire1 "))&&( speed <800)) {speed += Time.deltaTime * 240;} I have also edited my answer in reply to this error. You may also want to change the values of acceleration whether on the ground or not, since they're the same in your quesiton or maybe you left it like that intentionally, just making sure.
Dec 25 '11 at 12:54 PM
Rabwin
ok now it gives me more errors when i put it in it tells me more errors can you put it into your editor and tell me where im going wrong cause this is the final code i get here using UnityEngine; using System.Collections; public class speed : MonoBehaviour { }
Dec 26 '11 at 01:10 AM
cubelord
can i send you my project through email and have u set up the controls like left right accelerate and i can put you down as co developer needed a partner anyway
Dec 26 '11 at 06:24 AM
cubelord
(comments are locked)
|
