PHP
- 3 ответа
- 0 вопросов
0
Вклад в тег
rb.velocity = direction * speed;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 10;
public Animator animator;
private Rigidbody2D rb;
private Vector2 direction;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
direction.x = Input.GetAxisRaw("Horizontal");
direction.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", direction.x);
animator.SetFloat("Vertical", direction.y);
animator.SetFloat("Speed", direction.sqrMagnitude);
rb.velocity = direction * speed;
}
}