B
B
brumper2020-05-14 20:33:11
Unity
brumper, 2020-05-14 20:33:11

How to add flip 2d function?

How to add flip d 2d function?
Can't add flip function! Help me please!
using UnityEngine;
using System.Collections;

public class Control : MonoBehavior {
public float speed = 10f;

public bool Grounded = false;
public Transform GroundCheck;
public float GroundRadius = 0.2f;
public LayerMask wtfIsGround;

Rigidbody2D rig;

void Start() {
rig = GetComponent();


}

void Update () {

Grounded = Physics2D.OverlapCircle(GroundCheck.position, GroundRadius, wtfIsGround);

if (Input.GetKeyDown(KeyCode.Space) && Grounded) {
rig.AddForce(new Vector2(0, 800f));
}

float move;
move = Input.GetAxis("horizontal");
rig.velocity = new Vector2(move * speed, rig.velocity.y);

}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Taisu Black, 2020-05-14
@UnityEngineDanil

Hello! To do this, write the following lines of code)

void Flip()
    {
        if(Input.GetAxis("Horizontal") < 0)
        {
            transform.localRotation = Quaternion.Euler(0, 180, 0);
        }

        if (Input.GetAxis("Horizontal") > 0)
        {
            transform.localRotation = Quaternion.Euler(0, 0, 0);
        }

    }

And specify the flip function personally, I do it like this!5ebd85171a1d0430614521.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question