/// <summary> /// Breaks a random part of the hull /// </summary> private void breakRandom() { bool found = false; int i = 0; while (!found) { KeyboardKey[] row = grid.rows[Random.Range(0, 3)].keys; KeyboardKey key = row[Random.Range(0, row.Length)]; if (!key.hasALeak) { found = true; GameObject leak = Instantiate(Resources.Load("Leak")) as GameObject; leak.transform.SetParent(this.transform); leak.GetComponent <Leak>().init(key); audioSource.Play(); key.hasALeak = true; } else { i++; } if (i > 10) { return; } } }
/// <summary> /// Initialises the plank /// </summary> /// <param name="parent">Transform of hole to place this plank on top of.</param> public void init(Transform parent) { currentState = State.BUILDING; mouse = FindObjectOfType <Mouse>(); mouse.switchTool(Mouse.Tool.HAMMER); pauseMenu = FindObjectOfType <Pause.PauseMenu>(); transform.SetParent(parent); transform.localPosition = new Vector3(0.0f, 0.0f, parent.transform.position.z - 0.1f); key = transform.parent.GetComponent <Leak>().key; ring = transform.Find("Ring").gameObject.GetComponent <PulsingUI>(); clicksToBuild = Random.Range(1, 8); audioSource = GetComponent <AudioSource>(); playSoundFrom(placementSound); }
/// <summary> /// Initialises the leak /// </summary> /// <param name="key">The key used to plug this hole</param> public void init(KeyboardKey key) { this.key = key; currentState = State.LEAKING; transform.position = key.position; game = FindObjectOfType <Game>(); pauseMenu = FindObjectOfType <Pause.PauseMenu>(); Score.newLeak(); waves = FindObjectOfType <Waves>(); hole = transform.Find("Hole").gameObject; hole.transform.rotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)); // Random orientation keyIcon = transform.Find("Key").gameObject; keyIcon.transform.Find("Text").GetComponent <TextMesh>().text = key.keyCode.ToString(); particleSystem = GetComponentInChildren <ParticleSystem>(); }