Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zachypin · Jul 25, 2011 at 07:52 PM · guimovementinputwasd

Input trick question

I currently have my character moving with WASD. I have a GUI setup that I want to mimic the WASD movement. I was wondering if it were possible to have a function say if GUI Button pushed, then act as if Input.GetKeyDown("x") = true.

I'd like to do this because it's an easier way to do what I want, plus I'd just like to know :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Jul 25, 2011 at 08:04 PM

I have an on-screen WASD control that lets you push the buttons as though they were keys. I don't know if it's the best way, but what I did was use GUI.RepeatButton's and modified the MouseLook and FPSWalker scripts to have a new var like 'doVert' and 'doHorz' to accept these as though they were Inputs. A fragment:

 if (ml == null)
     ml = Camera.main.GetComponent(MouseLook);
 if (GUI.RepeatButton  (Rect (Screen.width - left, Screen.height - top, 44, 44), laTexture))
     if (ml)
         ml.doHorz = -.10f;
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zachypin · Jul 26, 2011 at 04:37 PM 0
Share

looks like the closest I'll get to what I'm thinking

avatar image
0

Answer by ConfinedDarkness · Jul 25, 2011 at 08:03 PM

Have a Vector2 variable that is changed depending on input. Then make the position of your GUI element be that variable.

eg:

var guiPosition : Vector2;

function Update () {

guiPosition.x += Input.GetAxis("Horizontal"); guiPosition.y += Input.GetAxis("Vertical");

}

function OnGUI () {

GUI.Box(Rect(guiPosition.x, guiPosition.y, 100, 100), "I am a box!");

}

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jul 25, 2011 at 10:11 PM 0
Share

I have to admit that the question is not that clear at the start but near the end he quite clearly says he want to use a GUI.Button to emulate a key-down so he can move his char with the GUI-buttons. Your solution will move a gui element with WASD which is kinda the opposite :D

avatar image ConfinedDarkness · Jul 25, 2011 at 10:38 PM 0
Share

Oh! Sorry I miss-read. I thought he wanted to move the GUI. I guess his question has been answered by dave.

avatar image zachypin · Jul 26, 2011 at 01:12 PM 0
Share

I was able to get my program working, but still don't have a direct answer to the question. I just didn't know if Unity supported a function that would say "Act like I just pushed 'a' ". So if I have WASD setup in code, ins$$anonymous$$d of adding the arrow keys to the code I could just write code that when pushing the arrow keys the game is taking it as input from WASD.

avatar image
0

Answer by ConfinedDarkness · Jul 26, 2011 at 01:53 PM

You can have a function named "W" that when you press the W key, do that function. Then you can have a GUI button that if it is pressed, do that function.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zachypin · Jul 26, 2011 at 04:37 PM 0
Share

yeah I know that. wanted to see if i could make a sort of hierarchy though so I don't have to do that. - push 'B' - Acts like you pushed 'A' - Pushing 'A' launches a function

avatar image ConfinedDarkness · Jul 26, 2011 at 05:06 PM 0
Share

Oh ok. Sorry i don't think that is possible.

avatar image zachypin · Jul 26, 2011 at 07:42 PM 0
Share

ooo welll. Would be a neat little function, but there are definitely a million ways around it, like the answer above.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Paper, Rock, Scissor 3 Answers

TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer

Two near-identical scripts cause a cat to jump in different ways - why? 2 Answers

NGUI: Button don't detect input if parent change position on-screen? 1 Answer

Bind Controller GUI to Input 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges