-
Notifications
You must be signed in to change notification settings - Fork 1
/
Week5 -GCScript.cs
82 lines (61 loc) · 1.62 KB
/
Week5 -GCScript.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
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//additional libraries
using TMPro;
using UnityEngine.SceneManagement;
public class GCScript : MonoBehaviour
{
//Grab the ship object
public GameObject ship;
//Grab the invader object
public GameObject invader;
public GameObject life;
public TMP_Text scoreText;
public int score = 0;
private int lives = 3;
public bool isDead = false;
// Start is called before the first frame update
void Start()
{
Instantiate(ship, new Vector3(0, -3), Quaternion.identity);
//draw 10 invaders across
for (int i = -5; i < 5; i++)
{
//draw 3 rows down
for (int j = 2; j < 5; j++)
{
Instantiate(invader, new Vector3(i, j), Quaternion.identity);
}
}
//Draw 3 Lives
for (int i=0; i < 3; i++)
{
Instantiate(life, new Vector3(i + 6, 4), Quaternion.identity);
}
}
void Update()
{
if (isDead ==true && Input.GetKeyDown(KeyCode.Space))
{
Instantiate(ship, new Vector3(0, -3), Quaternion.identity);
isDead = false;
}
}
public void AddScore()
{
score += 1;
scoreText.text = "Score: " + score;
}
public void killed()
{
if (lives == 0)
{
SceneManager.LoadScene("TitleScene");
}
isDead = true;
GameObject[] lifeSprites = GameObject.FindGameObjectsWithTag("Life");
Destroy(lifeSprites[lives-1]);
lives -= 1;
}
}