how to make my character move up and down (Vertical) in android control
Guys!! I'm a newb, please help me move my game character up and down in android mobile. what script should be added? I want this game to work on my android mobile.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Player : MonoBehaviour {
public float speed; public float increment; public float maxY; public float minY; private Vector2 targetPos; public int health; public GameObject moveEffect; public Animator camAnim; public Text healthDisplay; public GameObject spawner; public GameObject restartDisplay; private void Update() { if (health <= 0) { spawner.SetActive(false); restartDisplay.SetActive(true); Destroy(gameObject); } healthDisplay.text = health.ToString(); transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime); if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < maxY) { camAnim.SetTrigger("shake"); Instantiate(moveEffect, transform.position, Quaternion.identity); targetPos = new Vector2(transform.position.x, transform.position.y + increment); } else if (Input.GetKeyDown(KeyCode.DownArrow) && transform.position.y > minY) { camAnim.SetTrigger("shake"); Instantiate(moveEffect, transform.position, Quaternion.identity); targetPos = new Vector2(transform.position.x, transform.position.y - increment); } }