40 lines
969 B
C#
40 lines
969 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PaddleMovement : MonoBehaviour
|
|
{
|
|
[Range(0,2)]
|
|
public float movementSpeed = 1f;
|
|
|
|
private float currentMotion = 0f;
|
|
|
|
public float leftBound = -4.8f;
|
|
public float rightBound = 4.8f;
|
|
|
|
void FixedUpdate(){
|
|
var x = this.transform.position.x;
|
|
var y = this.transform.position.y;
|
|
var z = this.transform.position.z;
|
|
|
|
var paddleSize = this.GetComponent<BoxCollider>().bounds.size.x;
|
|
var newX = x + (-this.currentMotion * this.movementSpeed);
|
|
|
|
this.transform.position = new Vector3(
|
|
Mathf.Clamp(
|
|
newX,
|
|
leftBound + (paddleSize / 2),
|
|
rightBound - (paddleSize / 2)
|
|
),
|
|
y,
|
|
z
|
|
);
|
|
}
|
|
|
|
void OnRightLeft(InputValue value)
|
|
{
|
|
this.currentMotion = value.Get<float>();
|
|
}
|
|
}
|