Answer the question
In order to leave comments, you need to log in
How to call functions in ternary operator?
I am creating a control on one joystick, for two different objects. The X axis is responsible for one object, and the Z axis for another. To make them move in the right direction, I use ternary operators. Here is part of the code:
public float speed;
private float moveInput;
private Rigidbody rb;
public Joystick j;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
if (j.Horizontal < 0)
{
j.Vertical < 0 ? ((j.Vertical < j.Horizontal) ? moveVertical() : moveHorizontal()) : ((j.Vertical > -j.Horizontal) ? moveVertical() : moveHorizontal());
}
else
{
j.Vertical < 0 ? ((-j.Vertical > j.Horizontal) ? moveVertical() : moveHorizontal()) : ((j.Vertical > j.Horizontal) ? moveVertical() : moveHorizontal());
}
}
void moveHorizontal()
{
moveInput = -j.Horizontal;
rb.velocity = new Vector3(moveInput * speed, rb.velocity.y, rb.velocity.z);
}
void moveVertical()
{
moveInput = -j.Vertical;
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, moveInput * speed);
}
Answer the question
In order to leave comments, you need to log in
what fields are there in sh_refers_refers table? Is there a priority field in it? Can it be Null?
The fact is that you need to initialize all fields that do not have a default value or set them to this value
Who will filter the variables? Any self-respecting student will hack your site at once. Don't be lazy and learn PDO
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question