Question by 
               amrianoos · Apr 28, 2020 at 06:16 PM · 
                androidscripting problemmovementcontrolandroid iphone  
              
 
              how to make my character move up and down in android control (endless runner game)
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);
     }
 }
}
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
how to implement the reversal ,how to implement the reversal ... 0 Answers
Preventing smooth turning depending on input angle? 0 Answers
Move like 2D sonic in 3D space around in a spiral 1 Answer
Player not moving in the right direction instantly 1 Answer
how to shoot on different direction while moving away 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                