- Home /
 
               Question by 
               officerreciffo · Nov 05, 2014 at 04:26 PM · 
                guibuttonbuttonsgui-button  
              
 
              On Screen Button Controls
This is my the code I am using for keyboard input to move forwards, backwards and rotate. Although I want to move forwards, backwards and rotate with on screen buttons.
//--Script for movement--//
 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(CharacterController))]
 public class Controller : MonoBehaviour {
 
     public float MoveSpeed;
     public float RotationSpeed;
     CharacterController cc;
     // Use this for initialization
     void Start () {
     
         cc = GetComponent<CharacterController> ();
     }
     
     // Update is called once per frame
     void Update () {
         Vector3 forward = Input.GetAxis ("Vertical") * transform.TransformDirection (Vector3.forward) * MoveSpeed;
         transform.Rotate (new Vector3 (0, Input.GetAxis("Horizontal") * RotationSpeed * Time.deltaTime, 0));
         cc.Move (forward * Time.deltaTime);
         cc.SimpleMove (Physics.gravity);
     }
 }
 
 //-- buttons in a separate script --//
 
     public Rect upPosition = new Rect(200, 15, 150, 25);
     public GUIStyle upStyle = null;
     public Rect leftPosition = new Rect(200, 15, 150, 25);
     public GUIStyle leftStyle = null;
     public Rect rightPosition = new Rect(200, 15, 150, 25);
     public GUIStyle rightStyle = null;
 
     if(GUI.Button(upPosition, text, upStyle))
                 {
                     //move forward
                 }
                 if(GUI.Button(leftPosition, text, leftStyle))
                 {
                     //rotate left
                 }
                 if(GUI.Button(rightPosition, text, rightStyle))
                 {
                     //rotate right
                 }
I'm also open to other ways of doing this rather than sticking to my own method. Any help will be appreciated!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                