using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
[SerializeField]float moveSpeed = 0.5f;
[SerializeField]float paddingLeft;
[SerializeField]float paddingRight;
[SerializeField]float paddingTop;
[SerializeField]float paddingBottom;
Vector2 rawInput;
Vector2 minBounds;
Vector2 maxBounds;
void Start()
{
InsideBounds();
}
void Update()
{
Move();
}
void InsideBounds()
{
Camera mainCamera = Camera.main;
minBounds = mainCamera.ViewportToWorldPoint(new Vector2(0,0));
maxBounds = mainCamera.ViewportToWorldPoint(new Vector2(1,1));
}
void Move()
{
Vector3 delta = rawInput * moveSpeed * Time.deltaTime;
Vector2 newPos = new Vector2();
newPos.x = Mathf.Clamp(transform.position.x + delta.x , minBounds.x + paddingLeft, maxBounds .x + paddingRight);
newPos.y = Mathf.Clamp(transform.position.y + delta.y , minBounds.y + paddingBottom, maxBounds .y + paddingTop);
transform.position = newPos;
}
void OnMove(InputValue value)
{
rawInput = value.Get<Vector2>();
}
}
2021.3.1f1 The moment I started this course unity got a new version , so I switched back from 2021.3.2f1 to 1f1