private void OnTriggerEnter2D(Collider2D collision) { if (Layers == (Layers | (1 << collision.gameObject.layer))) { D2dDestructible.StampAll(transform.position, Size * transform.localScale, Angle, StampTex, Hardness, Layers); Destroy(gameObject); } if (transform.gameObject.tag == "bombe1") { if (collision.gameObject.tag == "tank2") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } else if (transform.gameObject.tag == "bombe2") { if (collision.gameObject.tag == "tank1") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } }
private void OnMelt(Collider2D col) { IEnumerable <Vector2> points = GetPointsInRange(col); foreach (var point in points) { Instantiate(_steam, point, new Quaternion()); D2dDestructible.StampAll(point, Vector2.one * col.gameObject.GetComponent <HeatHandler>().HeatMessage.Intensity / 100, 0, _stampTex, 1, 1 << LayerMask.NameToLayer(Layers.Ice) | 1 << LayerMask.NameToLayer(Layers.BackgroundIce)); } }
protected virtual void Start() { if (Stamp == true) { var stampPosition = transform.position; var stampAngle = StampRandomDirection == true?Random.Range(-180.0f, 180.0f) : 0.0f; D2dDestructible.StampAll(stampPosition, StampSize, stampAngle, StampTex, StampHardness, Mask); } if (Raycast == true && RaycastCount > 0) { var angleStep = 360.0f / RaycastCount; for (var i = 0; i < RaycastCount; i++) { var angle = i * angleStep; var direction = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); var hit = Physics2D.Raycast(transform.position, direction, RaycastRadius, Mask); var collider = hit.collider; // Make sure the raycast hit something, and that it wasn't a trigger if (collider != null && collider.isTrigger == false) { var strength = 1.0f - hit.fraction; // Do less damage if the hit point is far from the explosion // Add damage? if (DamagePerRay != 0.0f) { var destructible = collider.GetComponentInParent <D2dDestructible>(); if (destructible != null) { destructible.Damage += DamagePerRay * strength; } } // Add force? if (ForcePerRay != 0.0f) { var rigidbody2D = collider.attachedRigidbody; if (rigidbody2D != null) { var force = direction * ForcePerRay * strength; rigidbody2D.AddForceAtPosition(force, hit.point); } } } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (Layers == (Layers | (1 << collision.gameObject.layer))) { D2dDestructible.StampAll(transform.position, Size * transform.localScale, Angle, StampTex, Hardness, Layers); Transform instance = Instantiate(explode, transform.position, transform.rotation); instance.localScale = transform.localScale * Size; Destroy(instance.gameObject, 1); for (int i = 0; i < nbFragmentation; i++) { float dir = Random.Range(0, 180); if (dir < 90) { dir = 360 - dir; } else { dir -= 90; } Transform newBombe = Instantiate(bombe, transform.position, transform.rotation); newBombe.localScale = transform.localScale / 2; newBombe.GetComponent <Rigidbody2D>().velocity = Quaternion.Euler(0, 0, dir) * rb.velocity; Destroy(newBombe.gameObject, 1); } SoundControler._soundControler.PlaySound(SoundControler._soundControler._bomb); Destroy(gameObject); } if (transform.name == "bombe1") { if (collision.gameObject.tag == "tank2") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } else if (transform.name == "bombe2") { if (collision.gameObject.tag == "tank1") { Destroy(collision.gameObject); Destroy(gameObject); Instantiate(victory); } } }
// Use this for initialization void Start() { if (!OnlySound) { var circle = GetComponent <CircleCollider2D>(); //stamp float radius = circle.radius * ((transform.localScale.x + transform.localScale.y + transform.localScale.z) / 3f); D2dDestructible.StampAll(transform.position, new Vector2(radius, radius) * 2f, transform.localEulerAngles.z, Stamp, 1f); //end stamp //circlecast RaycastHit2D[] results = Physics2D.CircleCastAll(transform.position, radius, Vector2.zero, 0f); DamageTargets(results); } if (SoundNames.Count != 0) { MasterAudioSummoner.instance.PlayAudio(MasterAudioSummoner.instance.ExplosionSounds, SoundNames[Random.Range(0, SoundNames.Count)], 1f, 0.1f, transform.position, null); } }
void Detonate() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); D2dDestructible.StampAll(transform.position, new Vector2(1, 1) * explosionSize, 0f, stamp, 1); List <Player> players = GameObject.Find("GameManager").GetComponent <GameManager>().Players; foreach (Player player in players) { if (Vector2.Distance(player.transform.position, transform.position) < 2f) { int damage = Mathf.RoundToInt((1f - (Vector2.Distance(player.transform.position, transform.position) / 2f)) * damageCaused); gameManager.RegisterDamage(player, damage); player.attacked = true; player.GetComponent <Animator>().SetTrigger("attacked"); player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; Vector2 throwDirection = player.transform.position - transform.position; throwDirection.y = 1; player.GetComponent <Rigidbody2D>().velocity = throwDirection * (damage / 20f); } } Destroy(gameObject); }
private void Melt(HeatMessage message, Collider2D col) { if (timer > 0.25f) { timer = 0; } //if (Random.value < message.Intensity / 100) if (timer == 0) { IEnumerable <Vector2> points = GetPointsInRange(col); foreach (var point in points) { D2dDestructible.StampAll(point, Vector2.one * StampSize, 0, StampTex, 1, 1 << LayerMask.NameToLayer(Layers.Ice)); } //_polyCollider.points = MovePointsInwards(col); //_polyCollider.points = FlattenAngles(); //SetMeshFilterToPolyColliderPoints(); } timer += Time.deltaTime; }