• 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 /
This question was closed Sep 20, 2015 at 09:54 AM by jung-hyun-jong for the following reason:

Other

avatar image
Question by jung-hyun-jong · Sep 20, 2015 at 06:56 PM · c#guimove an object

Unity 2d make four directions (Up, Down, Right, Left. like RPG games) GUI buttons. Please help me.

First of all, my English ability just a little. I made character and character movement. (Also made Animation, Animator. Four directions. like RPG games) I made to move the keyboard,

Up - keyboard "W" Down - keyboard "S" Right - keyboard "D" Left - keyboard "A"

made in t$$anonymous$$s format. (t$$anonymous$$s is a PlayerControllers Script) Format is created as a keyboard works well. But, How to create a GUI button, I do not know what to add, what to PlayerControllers Script. I found roughly, there is a movie that uses GetAxisRaw and Rigidbody2D... I do not know at all. Here are attached to PlayerControllers Script.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControllers: MonoBehaviour {
     
     public Animator anim;
     public float speed;
 
 
     // Use t$$anonymous$$s for initialization
     void Start () {
         anim = GetComponent<Animator> ();
     }
 
 
 
     // Update is called once per frame
     void Update () {
 
 
         if (Input.GetKey (KeyCode.D)) 
         {
             transform.Translate(Vector2.right * speed);
         }
         
         if (Input.GetKey (KeyCode.A)) 
         {
             transform.Translate(-Vector2.right * speed);
         }
         if (Input.GetKey (KeyCode.W)) 
         {
             transform.Translate(Vector2.up * speed);
         }
         if (Input.GetKey (KeyCode.S)) 
         {
             transform.Translate(-Vector2.up * speed);
         }
 
 
 
 
 
 
 
 
         
         if (Input.GetKey (KeyCode.A)) {
             anim.SetBool ("Left", true);
             anim.SetBool ("Right", false);
             anim.SetBool ("Up", false);
             anim.SetBool ("Down", false);
         }
         if (Input.GetKey (KeyCode.S)) {
             anim.SetBool ("Down", true);
             anim.SetBool ("Up", false);
             anim.SetBool ("Left", false);
             anim.SetBool ("Right", false);
             
         }
         if (Input.GetKey (KeyCode.D)) {
             anim.SetBool ("Right", true);
             anim.SetBool ("Left", false);
             anim.SetBool ("Up", false);
             anim.SetBool ("Down", false);
         }
         if (Input.GetKey (KeyCode.W)) {
             anim.SetBool ("Up", true);
             anim.SetBool ("Down", false);
             anim.SetBool ("Left", false);
             anim.SetBool ("Right", false);
         }
         
         
         
         if(Input.GetKey (KeyCode.A)){
             anim.SetBool("Player_Left", true);
         }
         else{
             anim.SetBool ("Player_Left", false);
         }
         
         
         
         if(Input.GetKey (KeyCode.S)){
             anim.SetBool("Player_Down", true);
         }
         else{
             anim.SetBool ("Player_Down", false);
         }
         
         
         
         if(Input.GetKey (KeyCode.D)){
             anim.SetBool("Player_Right", true);
         }
         else{
             anim.SetBool ("Player_Right", false);
         }
         
         
         
         if(Input.GetKey (KeyCode.W)){
             anim.SetBool("Player_Up", true);
         }
         else{
             anim.SetBool ("Player_Up", false);
         }
 
     }
 
 }
 

I would want to ask. To create a GUI button of the four directions and I want to move character to four directions (Up, Down, Right, Left), but it doesn't work. I do not know what to do in PlayerControllers Script added. What should i do to work t$$anonymous$$s corrcetly?

Also attach a Game Scene. alt text

Please help me.

Thank you.

picture.jpg (11.7 kB)
Comment

People who like this

0 Show 0
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

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

UnassignedReferenceException: But wait; It's there! 0 Answers

How to control GUITextures within a single C# script? 1 Answer

Highscore GUI not working properly help 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