-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteract.cs
74 lines (57 loc) · 2.4 KB
/
Interact.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interact : MonoBehaviour {
public KeyCode DialogueInput = KeyCode.F;
public GameObject npc;
public GameObject player;
public GameObject instruction;
private bool canInteract = false;
void Start () {
//npc = this.gameObject;
player = GameObject.Find ("Player");
instruction.SetActive (false);
}
void Update () {
if (Input.GetKeyDown (DialogueInput)) {
if (npc.transform.position.x > player.transform.position.x && npc.transform.localScale.x < 0 && canInteract) {
Vector3 theScale = npc.transform.localScale;
theScale.x *= -1;
npc.transform.localScale = theScale;
}
else if (npc.transform.position.x < player.transform.position.x && npc.transform.localScale.x > 0 && canInteract) {
Vector3 theScale = npc.transform.localScale;
theScale.x *= -1;
npc.transform.localScale = theScale;
}
if (!player.GetComponent<PlayerMovement> ().isInteracting && canInteract == true && npc.tag == "Human" && FindObjectOfType<DialogueManager> ().endDialogue != true) {
player.GetComponent<PlayerMovement>().isInteracting = true;
npc.GetComponent<DialogueTrigger> ().TriggerDialogue ();
}else if (!player.GetComponent<PlayerMovement>().isInteracting && canInteract == true && npc.tag == "promptNPC" && FindObjectOfType<DialogueManager> ().endDialogue != true) {
player.GetComponent<PlayerMovement>().isInteracting = true;
npc.GetComponent<DialogueTrigger> ().TriggerDialogue ();
npc.GetComponent<DialogueTrigger> ().TriggerPrompt ();
} else if (player.GetComponent<PlayerMovement>().isInteracting && canInteract == true ){
if (FindObjectOfType<DialogueManager> ().complete == false) {
FindObjectOfType<DialogueManager> ().DisplayFullSentence ();
} else if (FindObjectOfType<DialogueManager> ().endDialogue == false && FindObjectOfType<DialogueManager> ().complete == true) {
FindObjectOfType<DialogueManager> ().DisplayNextSentence ();
}
}
}
}
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "Player") {
canInteract = true;
instruction.SetActive (true);
}
}
void OnTriggerExit2D(Collider2D col){
if (col.gameObject.tag == "Player") {
canInteract = false;
instruction.SetActive (false);
FindObjectOfType<DialogueManager> ().endDialogue = false;
FindObjectOfType<DialogueManager> ().EndPrompt ();
}
}
}