Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

i have a problem with Movement i need help

$
0
0
i have a problem with Movement in Ios And Android i touch and he's dont move i touch a left and right and he's don't moving using System.Collections; using System.Collections.Generic; using UnityEngine; public class P_Move : MonoBehaviour { private int xPos; private float t = 0.1f; public bool isTouch; // Update is called once per frame void Update () { if (isTouch == true) { //IOS & Android if (Input.touchCount > 0 && Game_init.gameStarted == true) { if (Input.GetTouch(0).position.x > Screen.width / 2 && t > 0.075f && xPos < 6.47) { xPos++; transform.localScale = new Vector2(0.1180117f, 0.1242387f); t = 0.0f; } if (Input.GetTouch(0).position.x < Screen.width / 2 && t > 0.075f && xPos > -6.47) { xPos--; transform.localScale = new Vector2(-0.1180117f, 0.1242387f); t = 0.0f; } t += Time.deltaTime; } } else { // KeyBoard if (Input.GetButton("Horizontal") && Game_init.gameStarted == true) { GetComponent().SetBool("Move Right", true); GetComponent().SetBool("Move Left", true); if (Input.GetAxis("Horizontal") > 0 && t > 0.075f && xPos < 6.62) { xPos++; transform.localScale = new Vector2(0.1180117f, 0.1242387f); t = 0.0f; } if (Input.GetAxis("Horizontal") < 0 && t > 0.075f && xPos > -6.47) { xPos--; transform.localScale = new Vector2(-0.1180117f, 0.1242387f); t = 0.0f; } t += Time.deltaTime; } } MovePlayer(); } void MovePlayer() { if (Input.GetButton("Horizontal") == false && isTouch == false) { GetComponent().SetBool("Move Right", false); GetComponent().SetBool("Move Left", false); GetComponent().SetBool("Stop", true); } if (Input.touchCount> 1 && isTouch == false) { GetComponent().SetBool("Move Right", false); GetComponent().SetBool("Move Left", false); GetComponent().SetBool("Stop", true); } Vector2 playerPos = gameObject.transform.position; playerPos.x = xPos; gameObject.transform.position = Vector2.Lerp(gameObject.transform.position, playerPos, 10 * Time.deltaTime); } }

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>