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 /
avatar image
0
Question by Turtle Dee · May 09, 2015 at 07:21 AM · movementtouchbeginnercontrols

I cant figure out how to change my simple Movement controls to touch, can anyone help?

Hello, I need some help on how to change this movement script of mine to touch controls if possible. I'm extremely new to this and have been looking all over for how to do this but it just doesn't make sense to me. If you could accomplish touch controls without changing much that would be awesome because the script is put onto the player and has restrictions that only work the way I currently have it setup. Here is what I have:

 using UnityEngine;
 using System.Collections;
 
 public class Movement : MonoBehaviour {
     
     float lerpTime;
     float currentlerpTime;
     float perc = 1;
     
     Vector3 startPos;
     Vector3 endPos;
 
     public float minX = 0;
     public float maxX = 2;
     public float minZ = 0;
     public float maxZ = 1;
 
 
     bool firstInput;
     public bool justJump;
 
 
 
     void Update () 
     {
 
 
         if (Input.GetButtonDown ("up") || Input.GetButtonDown ("down") || Input.GetButtonDown ("left") || Input.GetButtonDown ("right")) 
         {
             if(perc == 1)
             {
                 lerpTime = 1;
                 currentlerpTime = 0;
                 firstInput = true;
                 justJump = true;
             }
         }
         startPos = gameObject.transform.position;
         if(Input.GetButtonDown("right") && gameObject.transform.position == endPos && transform.position.x < maxX)
         {
             endPos = new Vector3(transform.position.x + 1,transform.position.y,transform.position.z);
         }
         if(Input.GetButtonDown("left") && gameObject.transform.position == endPos && transform.position.x > minX)
         {
             endPos = new Vector3(transform.position.x - 1,transform.position.y,transform.position.z);
         }
         if(Input.GetButtonDown("up") && gameObject.transform.position == endPos && transform.position.z < maxZ)
         {
             endPos = new Vector3(transform.position.x,transform.position.y,transform.position.z + 1);
         }
         if(Input.GetButtonDown("down") && gameObject.transform.position == endPos && transform.position.z > minZ)
         {
             endPos = new Vector3(transform.position.x,transform.position.y,transform.position.z - 1);
         }
         if (firstInput == true) {
             currentlerpTime += Time.deltaTime * 5;
             perc = currentlerpTime / lerpTime;
             gameObject.transform.position = Vector3.Lerp (startPos, endPos, perc);
             if (perc > 0.8F) {
                 perc = 1;
             }
             if (Mathf.Round (perc) == 1) {
                 justJump = false;
             }
         }
         
     }
 }
 
Comment
Add comment · Show 1
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 Turtle Dee · May 09, 2015 at 06:19 PM 0
Share

For people that might stumble into this question, I have figured out how to accomplish my problem and I no longer need any help. Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Meltdown · May 09, 2015 at 07:44 AM

Nobody is going to write your scripts for you, I would suggest learning how to build touch from scratch, there are hundreds of tutorials on the internet that explain how Unity and touch works, it's important when you are writing code that you understand what is going on.

Having someone write it for you will just make things even more difficult down the road when you need change things.

Take a look at this video tutorial

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 Turtle Dee · May 09, 2015 at 08:45 AM 0
Share

Hello and thank you for the reply. I realize after reading this question again that I came off as if I wanted some to write the code for me. I never intended to have someone do this for me as I really want to learn. Thank you for the video tutorial and the advise you gave me.

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

2 People are following this question.

avatar image avatar image

Related Questions

NPC movement 1 Answer

How can I make my characters movement better? 1 Answer

How to drag object along with dragging touch? 1 Answer

Help with iphone/android touch controls 2 Answers

Touch movement not working 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