Вот код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private bool canMove = true;
Rigidbody2D rb;
Animator anim;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
if (canMove)
{
//двигаем
StartCoroutine(StopJump(3f));
}
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
if (Input.GetAxis("Horizontal") == 0)
{
anim.SetInteger("Getfild", 1);
}
else
{
Flip();
anim.SetInteger("Getfild", 2);
}
}
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);
}
// Update is called once per frame
void FixedUpdate () {
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 3f, rb.velocity.y);
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("platform") && canMove)
{
StartCoroutine(StopJump(3f));
}
}
IEnumerator StopJump(float timer)
{
canMove = false;
yield return new WaitForSeconds(timer); //пауза в timer секунды
canMove = true;
}
void Jump()
{
rb.AddForce(transform.up * 5f, ForceMode2D.Impulse);
}
}
Принятый ответ
ma19ks:
Что именно? Как делал?не работает
`
ОЖИДАНИЕ РЕКЛАМЫ...
0
N7 Molot
5 лет назад
0
закинь булевую переменную как с передвижением, а если нормально сделана анимация, можно через ивент выловить конец прыжка, так же можно райкаст вниз кинуть, так тоже можно отловить возможность использовать прыжок
0
ma19ks
5 лет назад
0
N7 Molot:
не работает
0
N7 Molot
5 лет назад
0
ma19ks:
Что именно? Как делал?
Принятый ответ
Чтобы оставить комментарий, пожалуйста, войдите на сайт.