// Update is called once per frame void Update() { _timeLimit -= Time.deltaTime; _txt.text = ((int)_timeLimit).ToString(); if (_timeLimit <= 20) { if (_timeLimit <= 10) { ShowWarning(0.25f); } else { ShowWarning(0.5f); } } else { _txt.color = _startColor; _txt.fontSize = _startSize; } _stats.RemainingTime = (int)Mathf.Max(0, _timeLimit); if (_timeLimit < 0) { //TODO Put this somewhere else yo SceneManager.LoadScene("scn_gameover"); } if (_timeLimit % 10 <= 1) { _chat.PopUp(3); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.tag != "Cable" && collision.rigidbody.velocity.magnitude >= weight && Collided == false) { chat.PopUp(1); //TODO Add stuff here GameObject.Instantiate(Resources.Load("prefabs/pfb_particles_destroy"), transform.position, Quaternion.identity); scoreText = Instantiate(scoreTextPrefab, transform.position, Quaternion.identity) as GameObject; scoreText.GetComponent <TextMesh>().text = "-" + score.ToString() + " Sec"; scoreText.transform.DOBlendableMoveBy(Vector2.up, 4).OnComplete <Tween>(() => Destroy(scoreText)); uiScript.AddPunish(score); Collided = true; string trigger = Random.Range(0, 2) >= 1 ? "Angry" : "Shocked"; GameObject.FindGameObjectWithTag("Granny").GetComponent <Animator>().SetTrigger(trigger); ParentRoom.StuffSmashed(); //TODO Add rubble to room dust list for (int i = 0; i < _rubbleSpawnAmount; ++i) { GameObject go = GameObject.Instantiate(Resources.Load("prefabs/pfb_rubble"), transform.position, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 359.0f)), transform.parent) as GameObject; go.GetComponent <Rigidbody2D>().velocity = Random.insideUnitCircle.normalized * Random.Range(30.0f, 100.0f); ParentRoom.dust.Add(go); } GameObject.Instantiate(Resources.Load("prefabs/pfb_destruction_sound"), transform.position, Quaternion.identity); Destroy(gameObject); } }
void Update() { if (!done) { float dustInPercent = 0f; foreach (GameObject d in dust) { if (d != null) { dustInPercent += 1; } } if (dust.Count == 0) { dustInPercent = 0; } else { dustInPercent /= dust.Count; } tiles.ForEach((x) => { SpriteRenderer sr = x.GetComponent <SpriteRenderer>(); sr.color = Color.HSVToRGB(0, 0, ((1f - dustInPercent) * 0.5f) + 0.5f); }); mapIcons.ForEach((x) => { SpriteRenderer sr = x.GetComponent <SpriteRenderer>(); Color c = sr.color; sr.color = new Color(dustInPercent, (1f - dustInPercent), 0f); }); if (dustInPercent == 0) { done = true; GameObject o = Instantiate(doneMapIcon, transform.position, Quaternion.identity) as GameObject; if (perfect) { o.GetComponent <SpriteRenderer>().color = new Color(1, 1, 0); } else { o.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1); } if (dust.Count > 0) { FindObjectOfType <Sparkling>().PlaySparkle(transform.position, transform.lossyScale.x); Stats s = GameObject.FindGameObjectWithTag("Stats").GetComponent <Stats>(); s.Cleared++; s.ClearedPerfect += perfect ? 1 : 0; if (perfect) { chat.PopUp(2); } int sec = perfect ? -20 : -10; GameObject.FindGameObjectWithTag("uiTimer").GetComponent <UITimeBehaviour>().AddPunish(sec); GameObject textPrefab = GameObject.FindGameObjectWithTag("FloorManager").GetComponent <FloorComponents>().TextPrefab; GameObject text = Instantiate(textPrefab, transform.position, Quaternion.identity) as GameObject; text.GetComponent <TextMesh>().color = new Color(0, 1, 0); text.GetComponent <TextMesh>().text = (perfect ? "PERFECT! " : " ") + (-sec) + " Sec"; text.transform.DOBlendableMoveBy(Vector2.up, 4).OnComplete <Tween>(() => Destroy(text)); } } } }