How I'll do that when I come as a Player to some object , so the object will give me the key?
How I'll do that when I come as a Player to some object , so the object will give me the key? The point is that whenever I come into his BoxCollider , tells me that I bring him the key , that's ok . But when I'll get the key , I do not want to repeat , but I want to tell me something else. How should I do it? PS : the translation to Google . I come from Slovakia . PS2: DestroyWhenActivated It is a feature that does not need. PS3: Please advise someone , I've it all tangled up . Here are the scripts :
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class TextBoxManager : MonoBehaviour {
public GameObject textBox;
public GameObject textBox2;
public Text theText;
public Text theText2;
public TextAsset textFile; //pole pre Text
public TextAsset textFile2;
public string[] textLines;
public string[] textLines2;
public int currentLine;
public int currentLine2;
public int endAtLine;
public int endAtLine2;
public PlayerController player;
public bool isActive;
public bool isActive2;
public bool destroyWhenActivated;
public bool Lekarnicka;
void Start ()
{
player = FindObjectOfType<PlayerController> ();
Lekarnicka = false;
isActive = false;
if (textFile != null)
{
textLines = (textFile.text.Split ('\n'));
}
if (textFile2 != null)
{
textLines2 = (textFile2.text.Split ('\n'));
}
if (endAtLine == 0)
{
endAtLine = textLines.Length - 1;
}
if (endAtLine2 == 0)
{
endAtLine2 = textLines2.Length - 1;
}
if (isActive)
{
EnableTextBox ();
}
/*if (Lekarnicka)
{
EnableTextBox2 ();
}
*/
else
{
DisableTextBox ();
}
}
void Update()
{
if (!isActive)
{
return;
}
theText.text = textLines [currentLine];
if (Input.GetKeyDown (KeyCode.L))
{
currentLine += 1;
}
if (currentLine > endAtLine)
{
DisableTextBox ();
}
if (Lekarnicka == true && isActive2 == true)
{
theText2.text = textLines2 [currentLine2];
if (Input.GetKeyDown (KeyCode.L))
{
currentLine2 += 1;
}
if (currentLine2 > endAtLine2)
{
DisableTextBox ();
}
}
}
public void EnableTextBox()
{
textBox.SetActive (true);
isActive = true;
{
//player.canMove = false;
}
}
public void EnableTextBox2()
{
textBox2.SetActive (true);
}
public void DisableTextBox()
{
textBox.SetActive (false);
isActive = false;
//textBox2.SetActive (false);
}
public void DisableTextBox2()
{
textBox2.SetActive (false);
isActive2 = false;
}
public void ReloadScript2(TextAsset theText2)
{
if (theText2 != null)
{
textLines2 = new string[1];
textLines2 = (theText2.text.Split ('\n'));
}
}
public void ReloadScript(TextAsset theText)
{
if (theText != null)
{
textLines = new string[1];
textLines = (theText.text.Split ('\n'));
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player" && (isActive = true))
{
Lekarnicka = false;
textBox.SetActive (true);
isActive = true;
textBox2.SetActive (true);
isActive2 = false;
}
if (destroyWhenActivated)
{
Destroy (gameObject);
if (gameObject)
{
textBox.SetActive (false);
isActive = false;
textBox2.SetActive (false);
}
}
if (other.gameObject.tag == "Lekarnicka")
{
Lekarnicka = true;
//isActive = true;
isActive2 = true;
if (isActive2 == true)
{
isActive = false;
}
}
}
void OnTriggerExit(Collider other)
{
if (other.name == "Player")
{
textBox.SetActive (false);
isActive = false;
textBox2.SetActive (false);
DisableTextBox ();
DisableTextBox2 ();
}
}
}
Second Script:
using UnityEngine; using System.Collections;
public class ActivateTextAtLine : MonoBehaviour { public TextAsset theText; public TextAsset theText2; public int startLine; public int startLine2; public int endLine; public int endLine2; public TextBoxManager theTextBox; public TextBoxManager2 theTextBox2; public bool isActive; public bool isActive2; public bool Lekarnicka; public bool destroyWhenActivated;
void Start ()
{
isActive = false;
isActive2 = false;
if(isActive = false)
{
if (theTextBox = FindObjectOfType<TextBoxManager> ())
{
FindObjectOfType<TextBoxManager> ();
}
}
/*if(isActive = true)
if (theTextBox2 = FindObjectOfType<TextBoxManager2> ())
{
FindObjectOfType<TextBoxManager2> ();
}*/
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player" && (isActive = false))
{
theTextBox.ReloadScript (theText);
theTextBox.currentLine = startLine;
theTextBox.endAtLine = endLine;
theTextBox.EnableTextBox ();
if (destroyWhenActivated)
{
Destroy (gameObject);
}
}
if (other.gameObject.tag == "Lekarnicka")
{
Lekarnicka = true;
isActive2 = true;
}
if (other.gameObject.tag == "Player" && Lekarnicka == true)
{
theTextBox2.ReloadScript (theText2);
theTextBox2.currentLine2 = startLine2;
theTextBox2.endAtLine2 = endLine2;
theTextBox2.EnableTextBox2 ();
}
}
}
Third Script:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class TextBoxManager2 : MonoBehaviour {
public GameObject textBox2;
public Text theText2;
public TextAsset textFile2; //pole pre Text
public string[] textLines2;
public int currentLine2;
public int endAtLine2;
public PlayerController player;
public bool isActive;
public bool destroyWhenActivated;
public bool Lekarnicka;
void Start ()
{
player = FindObjectOfType<PlayerController> ();
Lekarnicka = false;
isActive = false;
if (textFile2 != null)
{
textLines2 = (textFile2.text.Split ('\n'));
}
if (endAtLine2 == 0)
{
endAtLine2 = textLines2.Length - 1;
}
if (isActive)
{
EnableTextBox2 ();
}
else
{
DisableTextBox2 ();
}
}
void Update()
{
/*if (!isActive)
{
return;
}
theText2.text = textLines2 [currentLine2];
if (Input.GetKeyDown (KeyCode.L))
{
currentLine2 += 1;
}
if (currentLine2 > endAtLine2)
{
DisableTextBox2 ();
}*/
}
public void EnableTextBox2()
{
textBox2.SetActive (true);
isActive = true;
}
public void DisableTextBox2()
{
textBox2.SetActive (false);
isActive = false;
}
public void ReloadScript(TextAsset theText2)
{
if (theText2 != null)
{
textLines2 = new string[1];
textLines2 = (theText2.text.Split ('\n'));
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Lekarnicka")
{
Lekarnicka = true;
textBox2.SetActive (true);
isActive = true;
// FindObjectOfType<TextBoxManager2> ();
// FindObjectOfType<ActivateTextAtLine2> ();
}
if (destroyWhenActivated)
{
Destroy (gameObject);
if (gameObject)
{
textBox2.SetActive (false);
isActive = false;
}
}
}
void OnTriggerExit(Collider other)
{
if (other.name == "Player")
{
textBox2.SetActive (false);
isActive = false;
}
}
}