ping_pong/Assets/Scripts/Player_01.cs
2025-03-30 20:12:08 +05:30

27 lines
652 B
C#

using UnityEngine;
public class Player_01 : MonoBehaviour
{
public float racketSpeed;
public string Inputname;
private Rigidbody2D rb;
private Vector2 racketDirection;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
float directionY = Input.GetAxisRaw(Inputname);
racketDirection = new Vector2(0,directionY).normalized;
}
private void FixedUpdate()
{
rb.linearVelocity = racketDirection * racketSpeed;
}
}