Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Oct 02, 2013 at 08:37 AM by Fattie for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Hmtinc · Oct 02, 2013 at 01:43 AM · move an object

Unity : Adapting mouse based game to touch controls

I developed a basic game in which the camera can be moved across the map using the WASD keys and i wanted to adapt the basic button actions to work on a touch screen , but I am unsure how to start.

Heres the c# code i currently have for moving the camera

 if (Input.anyKey && allowInput)
     {
         moved = false;
         if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { moved = true; Translate(Vector3.forward * Time.deltaTime * speed); }
         if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { moved = true; Translate(Vector3.back * Time.deltaTime * speed);}
         if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { moved = true; Translate(Vector3.left * Time.deltaTime * speed);}
         if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { moved = true; Translate(Vector3.right * Time.deltaTime * speed); }
 if (OnCamManuallyMoved != null && moved)
         {
             Vector3 pos = tr.position;
             if (pos.x < min_xz.x) pos.x = min_xz.x;
             if (pos.x > max_xz.x) pos.x = max_xz.x;
             if (pos.z < min_xz.y) pos.z = min_xz.y;
             if (pos.z > max_xz.y) pos.z = max_xz.y;
             tr.position = pos;
 
             OnCamManuallyMoved(); // call callback
         }
     }
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Oct 02, 2013 at 06:30 AM

This is a question of game design, not one of coding.

A good place to start would be to write down or draw, with a pen and paper, how you expect to map key presses to a touch screen. Do you want to tap areas of the screen to make the camera move there? Do you want a virtual keyboard to appear on screen showing U/D/L/R keys, or perhaps a virtual joystick? Many touch devices also have accelerometers and gyros - do you want to tilt the device to move the camera? Or do you want to tap at the edges of the screen?

All these are possible, but nobody here can decide which one you want. Until you get the design sorted out, forget about the code. If you get stuck implementing your chosen solution, come back and ask a specific question.

Comment
Add comment · 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
1

Answer by Ranger-Ori · Oct 02, 2013 at 07:18 AM

Well, you basically need to learn about the touch control system from scratch, not only by design, but understanding how it actually works, from a simple touch, to an object movement.

Import the "Standard Assets (Mobile)" built-in asset you have in your unity 3d. Check the scenes and examples, if you don't manage to understand what's going on, then go to youtube or google and start to read about the touch system.

http://docs.unity3d.com/Documentation/Manual/iphone-GettingStarted.html http://docs.unity3d.com/Documentation/ScriptReference/Touch.html

Good luck!

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity's Tech demo Procedural help? 0 Answers

Rotating an Object while Moving 0 Answers

how to work my game 0 Answers

Object rotating around object at two levels 1 Answer

Translate speed keeps changing 1 Answer


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