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 at 02:07 PM

Prasanna gravatar image

73 2 889 36

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

1 answer: 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 at 04:07 PM

HunterAMG gravatar image

4 3 4 6

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

Feb 04 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 at 07:54 PM HunterAMG

Thanks Hunter

Feb 06 at 07:33 AM Prasanna
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

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



Answers and Comments



asked: Feb 03 at 02:07 PM

Seen: 408 times

Last Updated: Feb 06 at 07:33 AM