Answer the question
In order to leave comments, you need to log in
How to make it possible to move up and down?
While there is such a line that makes the object constantly fly to the left:
public GameObject obj;
private float speed = 10f;
void Update()
{
StartCoroutine(moveObj());
}
IEnumerator moveObj () {
yield return new WaitForSeconds(1f);
obj.transform.Translate(Vector2.left * speed * Time.deltaTime);
}
Answer the question
In order to leave comments, you need to log in
What it is? Maybe I already flew away from new technologies in a day, to make a curutina to constantly pull to the left. I just don't understand why you need a delay of 1 second, but okay
Throw it into an update or curutina
float yPoz = Input.GetAxis("Vertical");
Vector2 direction = new Vector2(-1,yPoz);
obj.transform.Translate(direction * speed * Time.deltaTime);
yPoz calculates up or down, while direction calculates the direction. But, here it will move smoothly up or down, but if you need it sharply by 1 unit, then through the KeyCode you already need it
. At the expense of touches for android, this is another question, but there you just read it in Google and paste the code into the method
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question