IEnumerator SpawnRoutine() { RectTransform clickableRT = clickable.GetComponent <RectTransform> (); float clickableWidth = clickableRT.rect.width; float clickableHeight = clickableRT.rect.height; float padding = 20f; var screenSize = GetComponentInParent <CanvasScaler>().referenceResolution; int divX = Mathf.FloorToInt(screenSize.y / (clickableWidth)); int divY = Mathf.FloorToInt(screenSize.x / (clickableHeight)); List <Vector3> positions = new List <Vector3>(); for (int x = 0; x < divX; x++) { for (int y = 0; y < divY; y++) { positions.Add(new Vector3((x * clickableWidth) + padding, (y * clickableHeight) + padding)); } } foreach (Clickable click in clickables) { int i = UnityEngine.Random.Range(0, positions.Count); click.transform.position = positions [i]; positions.RemoveAt(i); click.gameObject.SetActive(true); yield return(new WaitForSeconds(0.5f)); } yield return(null); }
public void NotifyClicked(Clickable c) { Debug.Log("note " + c.name + " stage=" + stage); if (binocular.gameObject.activeSelf) { return; } if (stage >= stages.Count) { return; } if (c.GetComponent <ShovelClickable>()) { Destroy(c.gameObject); shovel.SetActive(true); return; } if (c.GetComponent <DigClickable>()) { if (shovel.activeSelf) { c.GetComponent <DigClickable>().Dig(mainChar.transform.position.x); } return; } if (Time.time - lastClickTime < 0.5f) { return; } lastClickTime = Time.time; StageDef sdef = stages[stage]; sdef.NotifyClicked(c); if (sdef.IsDone() && wonStages <= stage) { WinStage(); } }
private void DeactivateClickedObject() { if (clickedObject) { Outline ol = clickedObject.GetComponent <Outline>(); if (ol) { ol.enabled = false; } clickedObject = null; } }
// Update is called once per frame void Update() { /**if (!readyToPlay) * { * DebugLog("readyToPlay", ""+ readyToPlay, gameObject); * return; * }**/ if (Input.GetMouseButtonDown(0)) { //GameManager.instance.DebugLog("Input.GetMouseButtonDown(0)", "" + Input.GetMouseButtonDown(0), gameObject); if (binocular.gameObject.activeSelf) { return; } Ray ray = cam.ScreenPointToRay(Input.mousePosition); bool close = Mathf.Abs(mainChar.transform.position.x - ray.origin.x) < 1f; if (FindClickable(ray)) { if (close && targetClickable.GetComponent <DigClickable>() == null) { ReachedTarget(); } else { mainChar.SetGoTo(ray.origin.x); } } else { //GameManager.instance.DebugLog("character, ray: ", mainChar.transform.position.x + ", " + ray.origin.x, gameObject); mainChar.SetGoTo(ray.origin.x); } } }
private void OnClickHandler() { if (_doubleBonus) { _scores += 2; _progressBar.GetComponent <Image>().fillAmount += 1f / _maxScore; } else { _scores += 1; } if (_scores >= _maxScore) { _scores = _maxScore; _levelInfoLoader.AddPlayerResult("MY NAME", _timer.CurrentTime, _levelManager.LevelName); GameResultsView gameResultsView = Instantiate(_gameResultPrefab, _container); gameResultsView.Initialize(_levelManager.CurentLevel); _timer.Pause(true); } _currentScoreText.text = _scores.ToString() + "/" + _maxScore.ToString(); CheckBonuses(); if (_bigSizeBonus) { _clickable.GetComponent <Transform>().transform.localScale = new Vector3(2, 2, 1); } else { _clickable.GetComponent <Transform>().transform.localScale = new Vector3(1, 1, 1); } _progressBar.GetComponent <Image>().fillAmount += 1f / _maxScore; _clickSound.Play(); _clickable.SetPosition(GetRandomPosition()); float randomBonus = UnityEngine.Random.value; if (randomBonus < 0.2f) { System.Random random = new System.Random(); int bonus = random.Next(0, 3); if (bonus == 0) { _bigBonusItem.SetActive(true); _bigBonusItem.SetPosition(GetRandomPosition()); } else if (bonus == 1) { _freezeBonusItem.SetActive(true); _freezeBonusItem.SetPosition(GetRandomPosition()); } else if (bonus == 2) { _doubleBonusItem.SetActive(true); _doubleBonusItem.SetPosition(GetRandomPosition()); } } }