Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PaddleController : MonoBehaviour {
  6.     public enum Player {
  7.         PLAYER_ONE,
  8.         PLAYER_TWO
  9.     }
  10.  
  11.     public Player CurrentPlayer;
  12.     public float Speed;
  13.  
  14.     void Update() {
  15.         Vector3 movement = this.transform.position;
  16.         float moveSpeed = Speed * Time.deltaTime;
  17.        
  18.         if(CurrentPlayer == Player.PLAYER_ONE) {
  19.             if(Input.GetKey(KeyCode.W)) {
  20.                 movement.y += moveSpeed;
  21.             } else if (Input.GetKey(KeyCode.S)) {
  22.                 movement.y -= moveSpeed;
  23.             }
  24.         } else {
  25.             if(Input.GetKey(KeyCode.UpArrow)) {
  26.                 movement.y += moveSpeed;
  27.             } else if (Input.GetKey(KeyCode.DownArrow)) {
  28.                 movement.y -= moveSpeed;
  29.             }
  30.         }
  31.  
  32.         this.transform.position = movement;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement