@TUPC

Где ошибка в коде?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Управление : MonoBehaviour
{ 
    Rigidbody2D rb;
    Animator anim;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();

    }


    void Update()
    {
        
        if (Input.GetKeyDown(KeyCode.Space)) {
            
        

        }
        if (Input.GetAxis("Horizontal") == 0)
        {
            anim.SetInteger("stay", 1);
        } else {
            Flip();
            anim.SetInteger("stay", 2);
        }
    }
    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 FixedUpdate()
{
    rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
}
void jump()
{
    rb.AddForce(transform.up * 14f, ForceMode2D.Impulse);
}
}

5ca65d94b97fb225132698.png
  • Вопрос задан
  • 406 просмотров
Пригласить эксперта
Ответы на вопрос 2
@Sir_Akakii
У вас какая-то путаница в структуре кода.
Функции FixedUpdate и Jump находятся вне класса, последняя фигурная скобка вообще лишняя.
Ответ написан
Комментировать
kreo_OL
@kreo_OL
Медузко -_-
как то так
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Управление : MonoBehaviour
{
    Rigidbody2D rb;
    Animator anim;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();

    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {



        }
        if (Input.GetAxis("Horizontal") == 0)
        {
            anim.SetInteger("stay", 1);
        }
        else
        {
            Flip();
            anim.SetInteger("stay", 2);
        }
    }
    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 FixedUpdate()
    {
        rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
    }
    void jump()
    {
        rb.AddForce(transform.up * 14f, ForceMode2D.Impulse);
    }
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы