-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGuide.cs
More file actions
90 lines (71 loc) · 2.57 KB
/
Guide.cs
File metadata and controls
90 lines (71 loc) · 2.57 KB
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
83
84
85
86
87
88
89
90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Guide : MonoBehaviour
{
[SerializeField] private GameObject[] dialogues;
private int index = 0;
private bool facingRight = false;
private Rigidbody2D rb;
private Collider2D coll;
private float speed = 5f;
[SerializeField] private GameObject nutrigem;
[SerializeField] private GameObject bullet;
[SerializeField] private Transform firePoint;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
foreach(GameObject dialogue in dialogues) {
dialogue.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
if (index == dialogues.Length) {
Destroy(gameObject);
}
if (index == 0 && dialogues[index] == null) {
Flip();
rb.AddForce(new Vector2(0f, 350f));
rb.velocity = new Vector2(speed, rb.velocity.y);
index++;
} else if (index == 1 && nutrigem == null) {
Instantiate(bullet, firePoint.position, firePoint.rotation);
index++;
} else if (index == 3) {
if (dialogues[index] == null) {
index++;
}
} else if (index == 4) {
transform.SetPositionAndRotation(new Vector3(47f, 14f, 0f), Quaternion.identity);
if (dialogues[index] == null) {
index++;
}
}
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
Debug.Log("Player is in guide trigger zone.");
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f);
if ((other.transform.position.x < transform.position.x && facingRight) ||
(other.transform.position.x > transform.position.x && !facingRight)) {
Flip();
}
dialogues[index].SetActive(true);
}
}
private void OnCollisionEnter2D(Collision2D other) {
if (other.gameObject.CompareTag("Enemy")) {
dialogues[index].SetActive(true);
GetComponent<SpriteRenderer>().enabled = false;
index++;
transform.SetPositionAndRotation(new Vector3(36f, 3f, 0f), Quaternion.identity);
}
}
private void Flip() {
transform.localScale = new Vector3(-1 * transform.localScale.x, transform.localScale.y, transform.localScale.z);
facingRight = !facingRight;
}
}