So the idea is to get the cube i’m currently using to move 1.25 right and -1.25 left which I fixed in its code, and the other one uses touch in order to move the character, but after trying to export an .apk it doesn’t seem to work. Would really appreciate some help! Attached is the whole code I’m using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
//variables
public GameObject character;
private float speed = 5.0f;
private Vector3 pos;
private Transform tr;
private Rigidbody2D characterBody;
private float ScreenWidth;
// Use this for initialization
void Start()
{
pos = transform.position;
tr = transform;
ScreenWidth = Screen.width;
characterBody = character.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
int i = 0;
//loop over every touch found
while (i < Input.touchCount)
{
if (Input.GetTouch(i).position.x > ScreenWidth / 2 && tr.position == pos)
{
//move right
pos += new Vector3(1.25f, 0, 0);
}
if (Input.GetTouch(i).position.x < ScreenWidth / 2 && tr.position == pos)
{
//move left
pos += new Vector3(-1.25f, 0, 0);
}
++i;
}
}
}