Может кто-нибудь исправить код, сам только начинаю разбираться в C# , курсы начал смотреть. Если есть возможность, добавьте комментарии пожалуйста в код и напишите в чём проблема была
Код:
Синтаксис:
Используется csharp
using System.Collections.Generic;
using UnityEngine;
public class player_Control : MonoBehaviour
{
public Rigidbody2D RigBud;
public float movespeed;
public bool moveright;
public bool moveleft;
public bool moveup;
public bool movedown;
public bool jump;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask WoIG;
// Use this for initialization
void Start()
{
RigBud = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, -270);
Debug.Log("moving left");
}
if (Input.GetKey(KeyCode.RightArrow))
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 270);
Debug.Log("moving right");
}
if (Input.GetKey(KeyCode.UpArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 0);
Debug.Log("moving up");
}
if (Input.GetKey(KeyCode.DownArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 180);
Debug.Log("moving down");
}
if (moveright)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 270);
}
if (moveleft)
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, -270);
}
if (moveup)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 0);
}
if (movedown)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 180);
}
}
}
using UnityEngine;
public class player_Control : MonoBehaviour
{
public Rigidbody2D RigBud;
public float movespeed;
public bool moveright;
public bool moveleft;
public bool moveup;
public bool movedown;
public bool jump;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask WoIG;
// Use this for initialization
void Start()
{
RigBud = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, -270);
Debug.Log("moving left");
}
if (Input.GetKey(KeyCode.RightArrow))
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 270);
Debug.Log("moving right");
}
if (Input.GetKey(KeyCode.UpArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 0);
Debug.Log("moving up");
}
if (Input.GetKey(KeyCode.DownArrow))
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 180);
Debug.Log("moving down");
}
if (moveright)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, 270);
}
if (moveleft)
{
RigBud.velocity = new Vector2(-movespeed, RigBud.velocity.x);
transform.rotation = Quaternion.Euler(0, 0, -270);
}
if (moveup)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 0);
}
if (movedown)
{
RigBud.velocity = new Vector2(movespeed, RigBud.velocity.y);
transform.rotation = Quaternion.Euler(0, 0, 180);
}
}
}
Скрины проекта и настройки RigidBody(Может в них проблема):
https://imgur.com/a/dmKgj2D
Скорее всего зайду на форум завтра, заранее спасибо за помощь