R
R
Roman Tuzov2020-03-14 20:49:55
Unity
Roman Tuzov, 2020-03-14 20:49:55

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);
  }

But how can I make it so that I can control the object even up and down while it flies to the left, while keeping my finger on the screen? I heard that they do it through IDragHandler .
Do not criticize strictly, I'm still learning, I hope for understanding :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-03-14
@Hutson

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 question

Ask a Question

731 491 924 answers to any question