SHOW:
|
|
- or go back to the newest paste.
1 | using System.Collections; | |
2 | using System.Collections.Generic; | |
3 | using UnityEngine; | |
4 | ||
5 | public class PaddleScript : MonoBehaviour | |
6 | { | |
7 | //paddle speed | |
8 | public float speed = 5f; | |
9 | ||
10 | void Update() | |
11 | { | |
12 | Move(); | |
13 | } | |
14 | ||
15 | //movement function | |
16 | void Move() | |
17 | { | |
18 | //Getting information from left-right arrows or a-d keys to see which way we should move | |
19 | //GetAxisRaw returns only -1, 0, or 1 so our speed is constant | |
20 | float x = Input.GetAxisRaw("Horizontal"); | |
21 | ||
22 | //Calculating speed, direction and elapsed time between frames | |
23 | float speddDir = x * speed * Time.deltaTime; | |
24 | ||
25 | //changing the position of our paddle | |
26 | transform.position += new Vector3(speddDir, 0, 0); | |
27 | ||
28 | } | |
29 | } |