The question is answered, right answer was accepted
Unity Android Controlls with CrossPlatformInput
Hello, I have issues with moving of the player with AxisTouchButton script from CrossPlatformInput. I have done everything on this video Click and I am using my own code for movement and my character is not moving. Can you help me? Movement is in FixedUpdate.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
public class SimplePlatformController : MonoBehaviour
{
[HideInInspector]
public bool facingRight = true;
[HideInInspector]
public bool jump = false;
public float moveForce = 365f;
public float maxSpeed = 5f;
public float jumpForce = 1000f;
public Transform groundCheck;
public string jumpButton = "Jump";
public string horizontalctrl = "Horizontal";
private bool grounded = false;
private Animator anim;
private Rigidbody2D rb2d;
public Text countText1;
// public GameObject coinsound;
public float sec = 0.01f;
private string sceneNum;
public int count1;
void Awake()
{
anim = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
//coinsound.gameObject.SetActive(false);
}
void Start()
{
count1 = 0;
SetCountText();
sceneNum = SceneManager.GetActiveScene().name;
// Cursor.visible = false;
}
void Update()
{
grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
if (Input.GetButtonDown(jumpButton) && grounded)
{
jump = true;
moveForce = 320f;
}
if (grounded = true)
{
Debug.Log("grounded");
}
if (Input.GetButtonDown(jumpButton))
{
Debug.Log("jumpButton");
}
}
void FixedUpdate()
{
// float h = Input.GetAxis("Horizontal");
float h = CrossPlatformInputManager.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(h));
if (h * rb2d.velocity.x < maxSpeed)
rb2d.AddForce(Vector2.right * h * moveForce);
if (Mathf.Abs(rb2d.velocity.x) > maxSpeed)
rb2d.velocity = new Vector2(Mathf.Sign(rb2d.velocity.x) * maxSpeed, rb2d.velocity.y);
if (h > 0 && !facingRight)
Flip();
else if (h < 0 && facingRight)
Flip();
if (jump)
{
anim.SetTrigger(jumpButton);
rb2d.AddForce(new Vector2(0f, jumpForce));
jump = false;
}
Answer by Dexer125 · Apr 29, 2018 at 12:08 PM
Okay I figured it out, I need to switch platform to Android
Oh gooooood, thank you, i've been through sooooooooo many tutorial and i didn't understand why it didn't work.
It was so easy that nobody mentioned it!
thank youuuuuuuuuuuuu
Follow this Question
Related Questions
How to connect Windows and Android applications with bluetooth. 2 Answers
character controller stops working after build 3 Answers
What is the lable for the yaw axis 1 Answer
3d bird controller 0 Answers
Touchscreen Movement?? 1 Answer