private void OnTriggerExit2D(Collider2D collision) { if (collision.GetComponent <LevelCompleter>() == current_level) { current_level = null; } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.tag == "Level") { current_level = collision.GetComponent <LevelCompleter>(); } }
public void InvokeLevelCompletedEvent(bool win) { if (win) { LevelCompleter.UnlockLevel(levelNumber + 1); } LevelCompletedEvent.Invoke(win); }
void OnValidate() { if (!levelCompleter) { levelCompleter = transform.GetComponentInChildren <LevelCompleter>(); if (!levelCompleter) { GameObject levelCompleter = new GameObject("LevelCompleter"); levelCompleter.transform.parent = transform; SpriteRenderer sr = levelCompleter.AddComponent <SpriteRenderer>(); sr.sprite = Resources.Load <Sprite>("WhitePixel"); BoxCollider2D bc = levelCompleter.AddComponent <BoxCollider2D>(); bc.isTrigger = true; levelCompleter.AddComponent <BoxCollider2D>(); this.levelCompleter = levelCompleter.AddComponent <LevelCompleter>(); } } if (!blocks) { blocks = transform.GetComponentInChildren <Blocks>(); if (!blocks) { GameObject blocks = new GameObject("Blocks"); blocks.transform.parent = transform; this.blocks = blocks.AddComponent <Blocks>(); } } if (!environment) { if (transform.Find("Environment")) { environment = transform.Find("Environment"); } else { GameObject env = new GameObject("Environment"); env.transform.parent = transform; GameObject box = new GameObject("Box"); SpriteRenderer sr = box.AddComponent <SpriteRenderer>(); sr.sprite = Resources.Load <Sprite>("WhitePixel"); box.AddComponent <BoxCollider2D>(); box.transform.parent = env.transform; box.transform.localScale = new Vector2(3.5f, 3.5f); environment = env.transform; } } }
// Start is called before the first frame update void Start() { levelCompleter = GetComponent <LevelCompleter>(); earth = GetComponent <Earth>(); StartLevel(); }