Question by
unity_9025C88D549E9ACB120A · Dec 01, 2021 at 04:04 PM ·
c#androidplayerscript.programming
Game working in pc but not in Android While Testing
Guys I hade made Script which works fine on PC But When I use Unity Remote 5 to test On android Game appears in Android but Touch doesn't works I Tried with others devices But still It doesn't works
here Is My Player Movement Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
[SerializeField] private float playerSpeed = 2.0f;
[SerializeField] private float jumpHeight = 1.0f;
[SerializeField] private float gravityValue = -9.81f;
private Transform cameraMain;
private Player playerInput;
private void Awake()
{
playerInput = new Player();
controller = GetComponent<CharacterController>();
}
private void OnEnable()
{
playerInput.Enable();
}
private void OnDisable()
{
playerInput.Disable();
}
private void Start()
{
cameraMain = Camera.main.transform;
}
void Update()
{
groundedPlayer = controller.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
Vector2 movementInput = playerInput.PlayerMain.Move.ReadValue<Vector2>();
Vector3 move = (cameraMain.forward * movementInput.y + cameraMain.right * movementInput.x);
move.y = 0f;
controller.Move(move * Time.deltaTime * playerSpeed);
if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}
// Changes the height position of the player..
if (playerInput.PlayerMain.Jump.triggered && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
MouseButtonUp not always called 1 Answer
Need help with c# 1 Answer
How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers
Stuttering in build 0 Answers