Untitled
unknown
plain_text
a year ago
950 B
14
Indexable
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[Header("Values")]
[SerializeField, Range(0f, 25f)] float movementSpeed = 12f;
Vector2 rawInput;
Vector3 mousePos;
Rigidbody2D rb;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Aim();
}
void FixedUpdate()
{
Move();
}
void Aim()
{
Vector3 mousePosOnScreen = Mouse.current.position.ReadValue();
mousePos = Camera.main.ScreenToWorldPoint(mousePosOnScreen);
Vector2 directionToMouse = mousePos - transform.position;
transform.up = directionToMouse;
}
void Move()
{
rb.linearVelocity = rawInput * movementSpeed;
}
void OnMove(InputValue value)
{
rawInput = value.Get<Vector2>();
}
}Editor is loading...
Leave a Comment