So probably answer is near to my question but I can’t figure it out.
I have in my game small instructions. If player first time coming to some BoxCollider2D he can see first of two Canvas images. After he can press Space and this image should hide forever for this object and instead show another one.
//This class keeping methods
public class DialogManager : MonoBehaviour {
public GameObject dialogBox1;
public GameObject dialogBox2;
public Text dialogText1;
public Text dialogText2;
public bool dialogActive;
// Update is called once per frame
void Update () {
if (dialogActive && Input.GetKeyDown(KeyCode.Space)) {
dialogBox1.SetActive(false);
dialogActive = false;
}
}
//First Time
public void ShowBox1(string dialog) {
dialogActive = true;
dialogBox1.SetActive(true);
dialogText1.text = dialog;
}
//Another case
public void ShowBox2(string dialog)
{
dialogBox2.SetActive(true);
dialogText2.text = dialog;
}
}
//And this one FirstTImeDialogHolder
public class FTDialogHolder : MonoBehaviour {
public string dialog1;
public string dialogOther;
public GameObject instructImg;
private bool firstTime = true;
private DialogManager dialogManager;
private bool isTouching;
// Use this for initialization
void Start()
{
dialogManager = FindObjectOfType<DialogManager>();
}
// Update is called once per frame
void Update()
{
if (isTouching && !firstTime)
{
dialogManager.ShowBox2(dialogOther);
}
else
{
instructImg.SetActive(false);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (firstTime)
{
if (other.gameObject.name == "Player")
{
dialogManager.ShowBox1(dialog1);
}
}
if (other.gameObject.name == "Player")
{
isTouching = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.name == "Player")
{
firstTime = false;
isTouching = false;
}
}
}
Like i said at the start, answer is near to question. This scripts work perfect, and do what i exactly want to see…but for one of third different objects with this script. So all three objects have FTDialogHolder script and showing first one image (at the bottom of the screen). But the second one image (top-right corner) showing only for one of three objects (And yeah, i can have even more than 3 objects).
Canvas picture. At the start images are active(false).