Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PongPaddle : MonoBehaviour
- {
- //paddle speed
- public float speed = 5f;
- void Update()
- {
- Move();
- }
- //movement function
- void Move()
- {
- if(gameObject.name == "Paddle1")
- {
- //Getting information from up-down arrows or w-s keys to check which direction are we moving to
- //GetAxisRaw returns only -1, 0, 1 so the speed will be constant
- float y = Input.GetAxisRaw("Vertical");
- //calculating speed, direction and elapsed time
- float speddDir = y * speed * Time.deltaTime;
- //changing the position of the paddle
- transform.position += new Vector3(0, speddDir, 0);
- }
- if (gameObject.name == "Paddle2")
- {
- float y = Input.GetAxisRaw("Vertical2");
- float speddDir = y * speed * Time.deltaTime;
- transform.position += new Vector3(0, speddDir, 0);
- }
- }
- }
Add Comment
Please, Sign In to add comment