/
PlayerController.cs
54 lines (43 loc) · 1.12 KB
/
PlayerController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEngine;
using System.Collections;
/*
* File Name : PlayerController.cs
* Author : Austin Khamsisavadty 100942529
* Last Modified : 10/30/2016
* Date Last Modified : 10/30/2016
* Description : Controls player sprite
* Revision : 1.0
* */
public class PlayerController : MonoBehaviour {
[SerializeField]
private float speed = 0.08f;
private Transform _transform;
private Vector2 _currentPosition;
private float _playerInput;
//Initialization
void Start () {
_transform = gameObject.GetComponent<Transform>();
_currentPosition = _transform.position;
}
// Update is called once per frame
void FixedUpdate () {
_playerInput = Input.GetAxis ("Vertical");
_currentPosition = _transform.position;
//move up
if (_playerInput > 0) {
_currentPosition += new Vector2 (0, speed);
}
//move down
if (_playerInput < 0) {
_currentPosition -= new Vector2 (0, speed);
}
//player bounds
if (_currentPosition.y < -2.8f) {
_currentPosition.y = -2.8f;
}
if (_currentPosition.y > 2.45f) {
_currentPosition.y = 2.45f;
}
_transform.position = _currentPosition;
}
}