-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerContoller.cs
38 lines (33 loc) · 1022 Bytes
/
PlayerContoller.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerContoller : MonoBehaviour {
public Text scoreText;
public float speed = 10.0f;
private Rigidbody rb;
private int score;
// Start is called before the first frame update
void Start() {
rb = GetComponent<Rigidbody>();
score = 0;
SetScore();
}
// FixedUpdate is used for Physics actions
void FixedUpdate() {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Collectible")) {
other.gameObject.SetActive(false);
score = score + 10;
SetScore();
}
}
void SetScore() {
scoreText.text = "Score: " + score;
}
}