So I have been trying to code a game with touch functions, and i have been going through hourse of research and trial and error but it doesnt seem to ever work. I made 2 scripts first of which was the CharacterControls and then TouchControls, Character Controls Script: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharacterControls : MonoBehaviour { public GameObject playerBullet; public GameObject FirePoint; public float moveSpeed; public float jumpHeight; private float moveVelocity; public Transform groundCheck; public float groundCheckRadius; public LayerMask whatIsGround; private bool grounded; private Animator anim; private float playersx; // Use this for initialization void Start () { anim = GetComponent<Animator> (); playersx = transform.localScale.x; } void FixedUpdate(){ grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround); } // Update is called once per frame void Update () { anim.SetBool ("Grounded", grounded); #if UNITY_STANDALONE || UNITY_WEBPLAYER Move (Input.GetAxisRaw ("Horizontal")); if (Input.GetButtonDown ("Fire1")) { GameObject bullet01 = (GameObject)Instantiate (playerBullet); bullet01.transform.position = FirePoint.transform.position; } if(Input.GetKeyDown (KeyCode.Space) && grounded) { GetComponent<Rigidbody2D> ().velocity = new Vector2(GetComponent<Rigidbody2D> ().velocity.x, jumpHeight); } if(Input.GetKey (KeyCode.D)) { GetComponent<Rigidbody2D> ().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D> ().velocity.y); } if(Input.GetKey (KeyCode.A)) { GetComponent<Rigidbody2D> ().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D> ().velocity.y); } #endif anim.SetFloat ("Speed", Mathf.Abs (GetComponent<Rigidbody2D> ().velocity.x)); if (GetComponent<Rigidbody2D> ().velocity.x > 0) transform.localScale = new Vector3 (playersx, transform.localScale.y, transform.localScale.z); else if (GetComponent<Rigidbody2D> ().velocity.x < 0) transform.localScale = new Vector3 (-playersx, transform.localScale.y, transform.localScale.z); } public void Move(float moveInput) { moveVelocity = moveSpeed * moveInput; } } TouchControls Script: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TouchControls : MonoBehaviour { private CharacterControls thePlayer; void Start(){ thePlayer = FindObjectOfType<CharacterControls> (); } public void LeftArrow() { thePlayer.Move (-1); } public void RightArrow() { thePlayer.Move (1); } public void Stop(){ thePlayer.Move (0); } } Please Help, Thanks to anyone who is able to help me out.
Does the keyboard version work? If you put Debug.Log() inside those Left/Right arrow functions, does it get called? One difference there could be that this line gets called inside update loop, Move (Input.GetAxisRaw ("Horizontal")); but maybe these line gets only called once per button click? (from where and how you are calling these left right calls?) public void LeftArrow()