using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DialogueBoxBackgroundController : MonoBehaviour { public bool deployed = false; public bool deploying = false; public bool retiring = false; public Image bgImage; public float x = 0.01f; public float y = 0.01f; public float speed; // Use this for initialization void Start () { bgImage.transform.localScale = new Vector2(0,0); } // Update is called once per frame void Update () { } public void Deploy() { if (deploying == true) { bgImage.enabled = true; x = (x + speed); y = (y + speed); bgImage.transform.localScale = new Vector2(x, y); if (x >= 1 || y >= 1) { deploying = false; deployed = true; } } } public void Retire() { if (retiring == true) { x = (x - speed); y = (y - speed); bgImage.transform.localScale = new Vector2(x, y); if (x <= 0 || y <= 0) { retiring = false; deployed = false; bgImage.enabled = false; } } } private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { if (x <= 1 && y <= 1) { deploying = true; } } } private void OnTriggerExit2D(Collider2D other) { if (other.tag == "Player") { if (x >= 1 && y >= 1) { retiring = true; } } } }