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 Havil · Nov 11, 2018 at 08:21 PM · 2d gametouch controlscontrolstouchscreen

How do I change this 2D script to touch controls to go up and down with swipe or on screen buttons?

Plz help me with this player script i'm a beginner on unity and i'm making a 2D game i want to change the controls from key-inputs to touch control but i don't know how to make it work, i want to make the player move up or down a specific amount plz help and thank you for reading.

This is the script that i use for the movement

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class Player: MonoBehaviour {

 private Vector2 tragetPos;
 public float Yincrement;

 public float speed;
 public float maxHeight;
 public float minHeight;

 public int health = 3;

 public Text healthDisplay;




 private void Update()
 {


     healthDisplay.text = health.ToString();


     if (health <= 0)
     {

         SceneManager.LoadScene("GameOver");

     }




     transform.position = Vector2.MoveTowards(transform.position, tragetPos, speed * Time.deltaTime);


     if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < maxHeight) {
         tragetPos = new Vector2(transform.position.x, transform.position.y + Yincrement);

     } else if (Input.GetKeyDown(KeyCode.DownArrow) && transform.position.y > minHeight) {
         tragetPos = new Vector2(transform.position.x, transform.position.y - Yincrement);


     }
 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hectorux · Nov 11, 2018 at 11:58 PM

If you want just one finger, or one touch, the mouse inputs will work, something like mouse.delta.x(i dontt remember exaclty this line)

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 Havil · Dec 05, 2018 at 11:12 PM 0
Share

Can you plzzzz let me the code that i need to put in the script if you remember it i still haven't figured it out, what do i put ins$$anonymous$$d of the Get$$anonymous$$eyDown if statement i did put Get$$anonymous$$ouseDown but it doesn't work for me all i need is swipe up and down a specific amount,plz help me AND THAN$$anonymous$$ YOU SOOO $$anonymous$$UCH FOR CO$$anonymous$$$$anonymous$$ENTING ON THE QUESTION.

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

109 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 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 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 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 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 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 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

Touch input broken with multi-touch 1 Answer

Possible to get touch area data? 1 Answer

Android Touch Screen Button for touch and hold 1 Answer

Can't solve hitbox issues in mobile game 1 Answer

Touchscreen controls in a 2D game 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