Added scoring

This commit is contained in:
Gregory Campbell
2020-07-11 16:19:57 -04:00
parent 6faf425d06
commit 7e0e1002a6
3 changed files with 258 additions and 2 deletions
+7 -1
View File
@@ -29,7 +29,13 @@ public class EnemyScript : MonoBehaviour
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Bullet" || other.gameObject.tag == "Player")
if(other.gameObject.tag == "Bullet")
{
PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score")+1);
Destroy(gameObject);
}
if(other.gameObject.tag == "Player")
{
Destroy(gameObject);
}
+8 -1
View File
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GMScript : MonoBehaviour
{
@@ -12,14 +13,17 @@ public class GMScript : MonoBehaviour
private float obstacleTime = 0.0f;
private float enemySpawnTime;
private float enemyTime = 0.0f;
private float time = 0.0f;
private Transform playerPos;
private Text score;
void Start()
{
PlayerPrefs.SetInt("Score", 0);
obstacleSpawnTime = Random.Range(5.0f, 15.0f);
enemySpawnTime = Random.Range(5.0f, 15.0f);
score = GameObject.Find("Score").GetComponent<Text>();
}
@@ -27,11 +31,14 @@ public class GMScript : MonoBehaviour
void Update()
{
score.text = "Score: " + PlayerPrefs.GetInt("Score");
if(GameObject.FindWithTag("Player") != null)
{
playerPos = GameObject.FindWithTag("Player").transform;
}
time += Time.deltaTime;
obstacleTime += Time.deltaTime;
enemyTime += Time.deltaTime;