/
weeny
/
Game
Обзор
Документация
Войти
/
weeny
/
Game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
GAME/Assets/Scripts/Player.cs
46 строк
1 KB
weeny
upload files
30 янв 2026, 18:10
Верифицирован
30 янв 2026, 18:10
06daff7
Код
Авторство
О чём код?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { [SerializeField] private float movingSpeed = 10f; private Rigidbody2D rb; private void Awake() { rb = GetComponent<Rigidbody2D>(); } private void FixedUpdate() { Vector2 inputVector = new Vector2(0, 0); // Независимо собираем ввод по каждой клавише if (Input.GetKey(KeyCode.W)) { inputVector.y += 1f; } if (Input.GetKey(KeyCode.S)) { inputVector.y -= 1f; } if (Input.GetKey(KeyCode.A)) { inputVector.x -= 1f; } if (Input.GetKey(KeyCode.D)) { inputVector.x += 1f; } inputVector = inputVector.normalized; Debug.Log(inputVector); // Изменяем позицию игрока rb.MovePosition(rb.position + inputVector * (movingSpeed * Time.fixedDeltaTime)); } }