using System.Collections.Generic;
using System.Threading;
using UnityEngine;
public class unit_controler : MonoBehaviour
{
Animator animator;
Rigidbody2D rb;
SpriteRenderer sprite;
[SerializeField]
int speed;
public float jump;
public int ExtraJumpValue;
private int ExtraJump;
public Transform земля_чекер;
public float чек_радиус;
public LayerMask что_есть_земля;
[SerializeField]
GameObject хитбокс_атаки;
bool Атака = false;
public bool НаЗемле;
public Transform upPoint;
private bool сantStand;
public bool сrouching;
private void Start()
{
ExtraJump = ExtraJumpValue;
animator = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
sprite = GetComponent<SpriteRenderer>();
хитбокс_атаки.SetActive(false);
}
private void FixedUpdate()
{
//проверка на землю под ногами
НаЗемле = Physics2D.OverlapCircle(земля_чекер.position, чек_радиус, что_есть_земля);
сantStand = Physics2D.OverlapCircle(upPoint.position, чек_радиус, что_есть_земля);
//это движение игрока
if (Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(speed, rb.velocity.y);
if (НаЗемле == true && Атака == false && сantStand == false)
{
animator.Play("бег");
}
else if (НаЗемле == true && Атака == false && сantStand == true)
{
animator.Play("бег и присидание");
}
transform.localScale = new Vector3(4, 4, 1);
}
else if (Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-speed, rb.velocity.y);
if (НаЗемле == true && Атака == false && сantStand == false)
{
animator.Play("бег");
}
else if (НаЗемле == true && Атака == false && сantStand == true)
{
animator.Play("бег и присидание");
}
transform.localScale = new Vector3(-4, 4, 1);
}
else
{
rb.velocity = new Vector2(0, rb.velocity.y);
if (НаЗемле && сantStand == false)
{
if (!Атака)
{
animator.Play("покой");
}
}
if (НаЗемле && сantStand == true)
{
if (!Атака)
{
animator.Play("покой и присидание");
}
}
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && !Атака && сantStand == false)
{
if (НаЗемле == false && сantStand == false)
{
animator.Play("удар и прыжок");
}
else
{
Атака = true;
animator.Play("удар");
}
StartCoroutine(Атакавать());
}
if (Input.GetKeyDown(KeyCode.Mouse0) && !Атака && сantStand == true)
{
if (НаЗемле == true && сantStand == true)
{
Атака = true;
animator.Play("удар и присидание");
}
StartCoroutine(Атакавать());
}
//это все прыжок, лучше не трогать )
if (Input.GetKey(KeyCode.W) && сantStand == false)
{
if(Атака == false && сantStand == false)
{
animator.Play("прыжок");
}
}
if(НаЗемле == true && сantStand == false)
{
ExtraJump = ExtraJumpValue;
}
if((Input.GetKeyDown(KeyCode.W) && ExtraJump > 0) && сantStand == false)
{
rb.velocity = Vector2.up * jump;
ExtraJump--;
}else if (Input.GetKeyDown(KeyCode.W) && ExtraJump == 0 && НаЗемле == true)
{
rb.velocity = Vector2.up * jump;
}
crouch();
}
IEnumerator Атакавать()
{
хитбокс_атаки.SetActive(true);
yield return new WaitForSeconds(0.5f);
хитбокс_атаки.SetActive(false);
Атака = false;
}
void crouch()
{
if((Input.GetKey(KeyCode.LeftControl) || сantStand == true) && НаЗемле == true)
{
сrouching = true;
}
else
{
сrouching = false;
}
}
}
if
,for
и т.д. не блок кода, а одна операуия, то{ }
не нужны. Сотня строк мусора.