- Home /
i have a problem with Movement i need help
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 moveing
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)
{
GetComponent<Animator>().SetBool("Move Right", true);
GetComponent<Animator>().SetBool("Move Left", 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;
}
}
}
else
{
// KeyBoard
if (Input.GetButton("Horizontal") && Game_init.gameStarted == true)
{
GetComponent<Animator>().SetBool("Move Right", true);
GetComponent<Animator>().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<Animator>().SetBool("Move Right", false);
GetComponent<Animator>().SetBool("Move Left", false);
GetComponent<Animator>().SetBool("Stop", true);
}
if (Input.touchCount> 1 && isTouch == false)
{
GetComponent<Animator>().SetBool("Move Right", false);
GetComponent<Animator>().SetBool("Move Left", false);
GetComponent<Animator>().SetBool("Stop", true);
}
Vector2 playerPos = gameObject.transform.position;
playerPos.x = xPos;
gameObject.transform.position = Vector2.Lerp(gameObject.transform.position, playerPos, 10 * Time.deltaTime);
}
}
Comment