using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed = 10f;
public Vector2 maxVelocity = new Vector2(3, 5);
// Update is called once per frame
void Update()
{
var forceX = 0f;
var forceY = 0f;
var absVelX = Mathf.Abs(Rigidbody2D.velocity.x);
if (Input.GetKey("right"))
{
if (absVelX < maxVelocity.x)
forceX = speed;
}else if (Input.GetKey("left"))
{
if (absVelX < maxVelocity.x)
forceX = -speed;
}
Rigidbody2D.AddForce(new Vector2(forceX, forceY));
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed = 10f;
public Vector2 maxVelocity = new Vector2(3, 5);
// Update is called once per frame
void Update()
{
var forceX = 0f;
var forceY = 0f;
var absVelX = Mathf.Abs(Rigidbody2D.velocity.x);
if (Input.GetKey("right"))
{
if (absVelX < maxVelocity.x)
forceX = speed;
}else if (Input.GetKey("left"))
{
if (absVelX < maxVelocity.x)
forceX = -speed;
}
Rigidbody2D.AddForce(new Vector2(forceX, forceY));
}
}