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 /
  • Help Room /
avatar image
0
Question by Doggi124 · Dec 04, 2017 at 10:49 AM · androidgametouch controls

Unity Android game doesn't respond to touches

Hello. I have an Android game where user moves player by touching left and right side of the screen. I tried the game on Android and all worked OK. But one day it stopped working: buttons work but I can't control the Player by touching screen sides. I tried to reinstall Unity, delete Library folder and even tried other OS. It didn't help. How can I fix my project?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class MovingPlayer : MonoBehaviour
 {
 
     public float playerSpeed;
     public float maxPos = 2.7f;
 
     Vector3 position;
     public uiManager ui;
     public AudioManager am;
 
     public Text coinCount;
 
     int coin;
 
     bool currntPlatformAndroid = false;
 
     Rigidbody2D rb;
 
     public GameObject particleSystemPrefab;
 
     void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
 
 #if UNITY_ANDROID
         currntPlatformAndroid = true;
 #else
                 currentPlatformAndroid = false;
 #endif
 
         am.playerSound.Play();
 
     }
 
     // Use this for initialization
     void Start()
     {
         coin = 0;
         position = transform.position;
     }
 
 
     // Update is called once per frame
     void Update()
     {
 
         if (currntPlatformAndroid == true)
         {
             TouchMove();
             //AccelerometerMove();
         }
 
         else
         {
 
             position.x += Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime;
 
             position.x = Mathf.Clamp(position.x, -2.7f, 2.7f);
 
             transform.position = position;
         }
 
         position = transform.position;
         position.x = Mathf.Clamp(position.x, -2.7f, 2.7f);
 
         transform.position = position;
 
     }
 
     void OnCollisionEnter2D(Collision2D col)
     {
         if (col.gameObject.tag == "CubeObstacle")
         {
             //Destroy (gameObject);
             foreach (ContactPoint2D contact in col.contacts)
             {
                 Instantiate(particleSystemPrefab, contact.point, Quaternion.identity);
 
             }
             //gameObject.SetActive(false);
 
             GameOverActivated();
             ui.gameOverActivated();
             am.playerSound.Stop();
         }
 
         if (col.gameObject.tag == "Coin")
         {
             Destroy(col.gameObject);
             coin += 1;
             coinCount.text = coin.ToString();
 
             Debug.Log("Coin");
         }
 
     }
 
     public void GameOverActivated()
     {
         Time.timeScale = 0;
         PlayerPrefs.SetInt("coins", PlayerPrefs.GetInt("coins") + coin);
     }
 
 
     void AccelerometerMove()
     {
         float x = Input.acceleration.x;
 
         if (x < -0.1f)
         {
             MoveLeft();
         }
 
         else if (x > 0.1f)
         {
             MoveRight();
         }
 
         else
         {
             SetVelocityZero();
         }
     }
 
     void TouchMove()
     {
         if (Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             float middle = Screen.width / 2;
 
             if (touch.position.x < middle && touch.phase == TouchPhase.Began)
             {
                 MoveLeft();
             }
 
             else if (touch.position.x > middle && touch.phase == TouchPhase.Began)
             {
                 MoveRight();
             }
         }
         else
         {
             SetVelocityZero();
         }
     }
 
     public void MoveLeft()
     {
         rb.velocity = new Vector2(-playerSpeed, 0);
     }
 
     public void MoveRight()
     {
         rb.velocity = new Vector2(playerSpeed, 0);
     }
 
     public void SetVelocityZero()
     {
         rb.velocity = Vector2.zero;
     }
 }

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

0 Replies

· Add your reply
  • Sort: 

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

224 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My 2D Android game(in unity) is not working 1 Answer

Problems testing on android device 1 Answer

App Icon too zoomed in 1 Answer

Why is my multi touch not working? 1 Answer

How to move a gameobject from exactly where it was touch 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