TransWikia.com

Поворот персонажа в юнити 2d

Stack Overflow на русском Asked by Monster Clash on November 30, 2021

У меня поворачивается не персонаж, а всё остальное на сцене, помогите!!! Код прилагаю ниже.

using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Hero : MonoBehaviour {
    Rigidbody2D rb;
    // Use this for initialization
    int life = 100;
    int jump = 2;
    Animator anim;

    void Start () {
        rb = GetComponent<Rigidbody2D>();
        // Update is called once per frame
        anim = GetComponent<Animator>();
    }

    void Update () {
        if (Input.GetKeyDown(KeyCode.UpArrow) && jump>0) {
            pipirka();
            anim.SetInteger("popka", 2);
            jump--;
        } else {
            anim.SetInteger("popka", 1);
        }
   }

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

    void OnCollisionEnter2D (Collision2D shit) {
        if (shit.gameObject.tag == "Ground") {
            jump = 2;
        }
        if (shit.gameObject.tag == "zona") {
            Invoke("ReloadFuckingLevel", 1);
            life = 0;
        }
        if (shit.gameObject.tag == "damage") {
            if (life > 10) {
                life = life - 10;
            } else {
                life = life - 10;
                Invoke("ReloadFuckingLevel", 1);
            }
        }
    }

    void OnGUI () {
        GUI.Box(new Rect(0, 0, 100, 30), "life = " + life);
    }

    void ReloadFuckingLevel () {
        Application.LoadLevel(Application.loadedLevel);
    }

    void FixedUpdate () {
        rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 7f, rb.velocity.y);
        Flip();
    }

    void pipirka() {
        rb.AddForce(transform.up * 14f, ForceMode2D.Impulse);
    }
}

One Answer

Вызывай на камере flip () в тоже время, когда у персонажа, но вместо 180 поставь 0

Answered by Kureshik on November 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP