K
K
KurwaTM2021-04-26 19:22:01
C++ / C#
KurwaTM, 2021-04-26 19:22:01

How to check if x or y is increasing?

Hello. I have a player movement script in Unity and I need to write true when x or z changes in bool value . For example:

float x,z;
bool isMoving;
if(x (здесь проверка) || z (здесь проверка) ){
isMoving = true
}else {
isMoving = false;
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
freeExec, 2021-04-26
@KurwaTM

бул = х != старый_х

I
Ilsk, 2021-04-26
@Ilsk

< , > some value

V
Vasily Bannikov, 2021-04-26
@vabka

Store the old value and compare with it

V
Vitaly Kachan, 2021-04-27
@MANAB

If you need to keep track of transform.position.x then through a comparison on each frame. If someone from the outside gives you a position (for example, a server, or a controller), then you can make x a property and add a check to set, like

private float x = 0;
private bool b = false;
public float X
{
    get { return x; }
    set { b = value != x; x = value; }
}

Well, or a method to write with the same logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question