44 lines
990 B
C#
44 lines
990 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
|
|
Rigidbody2D rb;
|
|
|
|
float walkSpeed = 4f;
|
|
float speedLimiter = 0.7f;
|
|
float inputHorizontal;
|
|
float inputVertical;
|
|
|
|
void Start()
|
|
{
|
|
rb = gameObject.GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
inputHorizontal = Input.GetAxisRaw("Horizontal");
|
|
inputVertical = Input.GetAxisRaw("Vertical");
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
if(inputHorizontal != 0 || inputVertical != 0)
|
|
{
|
|
if(inputHorizontal != 0 && inputVertical != 0)
|
|
{
|
|
inputHorizontal *= speedLimiter;
|
|
inputVertical *= speedLimiter;
|
|
}
|
|
rb.velocity = new Vector2(inputHorizontal * walkSpeed, inputVertical * walkSpeed);
|
|
}
|
|
else
|
|
{
|
|
rb.velocity = new Vector2(0f, 0f);
|
|
}
|
|
}
|
|
|
|
}
|