private void Start() { if (_tpPrefab == null) { _tpPrefab = (GameObject)Resources.Load("Teleporter"); } _collider = GetComponent <Collider2D>(); ParentRoom = transform.GetComponentInParent <Room>(); if (Demo) { //TODO: Remove this, only for demo purposes ParentRoom.TriggerTransition(this); } if (_collider != null && !_collider.isTrigger) { Debug.LogWarning($"Collider on transition point \"{name}\" is not a trigger, but it needs to be.", gameObject); } if (PlayerCanUse && _collider == null) { Debug.LogWarning($"Transition point \"{name}\" was marked as player usable but has no Collider2D, so nothing will happen.", gameObject); } if (GetComponent <SpriteRenderer>() == null) { var obj = Instantiate(_tpPrefab, transform, true); obj.transform.position = transform.position; obj.transform.localScale = _collider.bounds.size * 0.66f; _tpSprite = obj.GetComponent <SpriteRenderer>(); } }
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); } }
private void OnTriggerEnter2D(Collider2D collision) { if (!collision.CompareTag("Player")) { return; } if (OnCooldown) { return; } if (!EnemiesDead) { Debug.Log("Player was denied entry to transition because not all enemies are dead"); return; } if (!PlayerCanUse) { Debug.LogWarning("Player was denied entry to transition point", gameObject); return; } if (LinkedRoom == null) { if (PlayerCanUse) { Debug.LogError($"Linked room wasn't set for point \"{name}\" in room \"{ParentRoom.name}\" - please link to another room", gameObject); return; } else { Debug.LogWarning("Linked room wasn't set for non-usable point - probably fine, just FYI", gameObject); } } ParentRoom.TriggerTransition(this); }