-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerController.cs
70 lines (48 loc) · 2.06 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
private Rigidbody rigidBody;
public float speed;
public Text countText; // from the UI
private float zAxis;
private float xAxis;
private int gameCount;
private void Start()
{
// the only comnponant you variable you do not have to work initialize is transform the machione will not know what youyr talking about if you dont do this
//need to initialize the variable - so it knows what rigid body its getting
// in code you arte simply communicating with the machgine here
rigidBody = GetComponent<Rigidbody>();
gameCount = 0;
SetCountText(); //must haver to string to convert it to a string
}
private void Update()
{
xAxis = Input.GetAxis("Horizontal");
zAxis = Input.GetAxis("Vertical");
}
void FixedUpdate()
{
//initially did not run because speed was 0 so everything esle was 0 - overall a better and more efficient way
Vector3 movement = new Vector3(xAxis, 0.0f, zAxis); //create a new Vector3 variable to hold all the values of each axis with the get axis float variables
rigidBody.AddForce(movement * speed); // we do not need top place vector three in this line of code because it is already stored in the variables
}
void OnTriggerEnter (Collider other) //dertects a collider
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
gameCount = gameCount + 1;
SetCountText();
//again game objecect is the instance of the GameObject class
}
//game object set active is the code equivelent to setting the active check mark foir any object in the unity engine in the unity layer it's a check mark sop it's bool
}
void SetCountText()
{
countText.text = "Count: " + gameCount.ToString();
}
}