Y
Y
Yura Mailler2021-03-08 10:34:49
Unity
Yura Mailler, 2021-03-08 10:34:49

How to stop an object in place using code?

Hello! It is necessary that when reaching the object could not move higher, but at the same time it could move to the right and left, how to implement this with 2D?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-03-08
@Yura111

var pos = transform.position;
if (pos.y > 5)
   pos.y = 5;
transform.position = pos;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question