Finished tutorial
This commit is contained in:
@@ -19,9 +19,9 @@ public class Dropper : MonoBehaviour
|
||||
{
|
||||
if (Time.time > timeToWait)
|
||||
{
|
||||
Debug.Log("Lookout below!");
|
||||
rb.useGravity = true;
|
||||
meshRenderer.enabled = true;
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
public class Mover : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float moveSpeed = 5f;
|
||||
[SerializeField] Camera mainCamera;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
@@ -2,12 +2,14 @@ using UnityEngine;
|
||||
|
||||
public class ObjectHit : MonoBehaviour
|
||||
{
|
||||
[SerializeField] int damageAmount = 10;
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
if (other.gameObject.tag == "Player")
|
||||
if (other.gameObject.tag == "Player" && gameObject.tag != "Hit")
|
||||
{
|
||||
GetComponent<MeshRenderer>().material.color = Color.black;
|
||||
gameObject.tag = "Hit";
|
||||
other.gameObject.GetComponent<PlayerStats>().TakeDamage(damageAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
53
Assets/Scripts/PlayerStats.cs
Normal file
53
Assets/Scripts/PlayerStats.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEditor.Search;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerStats : MonoBehaviour
|
||||
{
|
||||
[SerializeField] int maxHealth = 100;
|
||||
int currentHealth;
|
||||
[SerializeField] float timeRemaining = 60f;
|
||||
[SerializeField] TextMeshProUGUI healthText, timeText;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
healthText.text = "Health: " + currentHealth.ToString();
|
||||
timeText.text = "Time: " + Mathf.RoundToInt(timeRemaining).ToString();
|
||||
InvokeRepeating("CountdownTimer", 1f, 1f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void TakeDamage(int damageAmount)
|
||||
{
|
||||
currentHealth -= damageAmount;
|
||||
healthText.text = "Health: " + currentHealth.ToString();
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
void Die()
|
||||
{
|
||||
Debug.Log("Player has died.");
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
void CountdownTimer()
|
||||
{
|
||||
if (timeRemaining > 0)
|
||||
{
|
||||
timeRemaining -= Time.deltaTime;
|
||||
timeText.text = "Time: " + Mathf.RoundToInt(timeRemaining).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Time's up!");
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayerStats.cs.meta
Normal file
2
Assets/Scripts/PlayerStats.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b57c3e49128c1f2459de912b7faaedc0
|
||||
@@ -1,14 +1,29 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class Scorer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] TextMeshProUGUI scoreText;
|
||||
[SerializeField] int maxHits;
|
||||
int hits = 0;
|
||||
void Start()
|
||||
{
|
||||
hits = 0;
|
||||
scoreText.text = "Hits: " + hits.ToString();
|
||||
}
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
if (other.gameObject.tag != "Hit")
|
||||
{
|
||||
if (hits < maxHits)
|
||||
{
|
||||
hits++;
|
||||
Debug.Log("You've bumped into something this many times: " + hits);
|
||||
scoreText.text = "Hits: " + hits.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Assets/Scripts/Tipper.cs
Normal file
23
Assets/Scripts/Tipper.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class Tipper : MonoBehaviour
|
||||
{
|
||||
Rigidbody rb;
|
||||
[SerializeField] float forceAmount = 10f;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void TipObject()
|
||||
{
|
||||
rb.AddTorque(transform.forward * forceAmount, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Tipper.cs.meta
Normal file
2
Assets/Scripts/Tipper.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c297212ebac7b1b4c8307da80f627ea7
|
||||
15
Assets/Scripts/TipperTrigger.cs
Normal file
15
Assets/Scripts/TipperTrigger.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TipperTrigger : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject[] tippers;
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.gameObject.tag == "Player")
|
||||
{
|
||||
foreach (GameObject tipper in tippers)
|
||||
tipper.GetComponent<Tipper>().TipObject();
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/TipperTrigger.cs.meta
Normal file
2
Assets/Scripts/TipperTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb01b3b511a61a84ca0ec07f458c577a
|
||||
Reference in New Issue
Block a user