x


Before updating to Windows 10 you may need to return your Pro license. More information here

[Closed] Movements Using GUI Button

Hello,I've been unlucky in searching for a solution on the furums which I am not able to find. I need to figure out how to make it possible for a classic 3rd person character to be controlled by GUI butons (arrows) instead of the cassual WASD style

more ▼

asked Feb 03, 2014 at 02:07 PM

avatar image

Prasanna
280 6 897 53

(comments are locked)
10|3000 characters needed characters left

The question has been closed Dec 04, 2014 at 04:39 AM by Prasanna for the following reason:

The question is answered, right answer was accepted


2 answers: sort voted first

I'm New to Unity but I think I can help you. You could try this approach:

 public void OnGUI(){
 if (GUI.Button (new Rect (65,10,48,48),"Left")){
         object.transform.velocity=(new Vector 3(-10,0,0));    
 
         }
 }

Of course you need to change the object, size and position of your button (and eventually the Style and/or Skin of the button) and the magnitude of the Velocity.

more ▼

answered Feb 03, 2014 at 04:07 PM

avatar image

HunterAMG
39 4 4 6

Hello HunterAMG, I Got this ERROR "" 'object' does not contain a definition for `transform' ""

Feb 04, 2014 at 05:59 AM Prasanna

As I said, you need to change "object" for the object you want to control. If this script is attached to the object just delete "object." i.e just "transform.velocity" Otherwise declare "object" or whatever you want the variable to be called as a public gameObject and use the Inspector to assign the object to be controlled.

Feb 04, 2014 at 07:54 PM HunterAMG

Thanks Hunter

Feb 06, 2014 at 07:33 AM Prasanna
(comments are locked)
10|3000 characters needed characters left

May be this will help Someone..

 if(Input.touchCount > 0)
         if (Up_Arrow.HitTest(Input.GetTouch(0).position))
         {
             if (Input.GetTouch(0).phase == TouchPhase.Stationary)
             {
                 Character_Animation = Animations.Movement;
                 transform.Translate(MoveDirection * Speed * Time.deltaTime);
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 180, 0), 1.0f);
             }
             if(Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Character_Animation = Animations.Idle;
             }
         }
         else if (Down_Arrow.HitTest(Input.GetTouch(0).position))
         {
             if (Input.GetTouch(0).phase == TouchPhase.Stationary)
             {
                 Character_Animation = Animations.Movement;
                 transform.Translate(MoveDirection * Speed * Time.deltaTime);
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, 0), 1.0f);
             }
             if(Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Character_Animation = Animations.Idle;
             }
         }
         else if (Left_Arrow.HitTest(Input.GetTouch(0).position))
         {
             if (Input.GetTouch(0).phase == TouchPhase.Stationary)
             {
                 Character_Animation = Animations.Movement;
                 transform.Translate(MoveDirection * Speed * Time.deltaTime);
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 90, 0), 1.0f);
             }
             if(Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Character_Animation = Animations.Idle;
             }
         }
         else if (Right_Arrow.HitTest(Input.GetTouch(0).position))
         {
             if (Input.GetTouch(0).phase == TouchPhase.Stationary)
             {
                 Character_Animation = Animations.Movement;
                 transform.Translate(MoveDirection * Speed * Time.deltaTime);
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 270, 0), 1.0f);
             }
             if(Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Character_Animation = Animations.Idle;
             }
         }

Ofcourse you have to declare the variables for guitexture and drag our guitexture for this variable.

more ▼

answered Dec 04, 2014 at 04:38 AM

avatar image

Prasanna
280 6 897 53

(comments are locked)
10|3000 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x256

asked: Feb 03, 2014 at 02:07 PM

Seen: 764 times

Last Updated: Dec 04, 2014 at 04:38 AM