// Use this for initialization void Start() { //Cache componnets; audioSource = GetComponent <AudioSource>(); gameOverPanelCanvas = uI.gameOverPanel.GetComponent <CanvasGroup>(); //Set gameover panel alpha to 0; gameOverPanelCanvas.alpha = 0; quadPrefab = (RectTransform)Instantiate(quadPrefab, Vector3.one * 1000, quadPrefab.rotation); //Instatiate movable quad prefab; quad = quadPrefab.GetComponent <MovableQuad>(); //Cache quad behaviour; //Set quad object as child of GameBox; quadPrefab.SetParent(gameBox); //Set hieararhy position so score text will draw under moveable quad; uI.scoreText.rectTransform.SetSiblingIndex(0); quadPrefab.SetSiblingIndex(1); //Disable movable quad object, we wont draw it at the start; quadPrefab.gameObject.SetActive(false); //Start coroutine to call game box animation; StartCoroutine("GetReady"); //Start corotine to enable and position moveable quad; StartCoroutine("SetRandomQuadPosition"); //Randomize panels names; RandomizePanels(); //Set up buttons listeners; uI.restartBtn.onClick.AddListener(() => { PlaySFX(audioSource, uI.clickSFX); //Play click sound effect; Restart(); //Call restart function; }); uI.quitBtn.onClick.AddListener(() => { PlaySFX(audioSource, uI.clickSFX); //Play click sound effect; StartCoroutine("QuitGame"); //Call quit game coroutine; }); //Set time to time for move value; time = timeForMove; //Load best score; bestScore = PlayerPrefs.GetInt("Best"); }
/// <summary> /// you should use that function instead of OnEnable() /// </summary> public override void OnCustomEnable() { base.OnCustomEnable(); _attractorQuad = (MovableQuad)GetTarget <MovableShape>(); }