private void addForce(Rigidbody2D rigBody) { RaycastHit2D rh = Physics2D.Linecast(transform.position, rigBody.transform.position); float force = (addForce(rh.distance)); float angle = getAngle(transform.position, rigBody.transform.position); Vector2 forceVector = new Vector2(-Mathf.Cos(angle), -Mathf.Sin(angle)); forceVector *= force; Debug.DrawRay(rigBody.transform.position, forceVector.normalized, Color.cyan, 5f, false); rigBody.AddForceAtPosition(forceVector, rh.point); if (rigBody.GetComponent <Snappable>()) { if (rigBody.GetComponent <Snappable>().snapOnExplode) { rigBody.GetComponent <Snappable>().destroy(); } } if (rigBody.GetComponent <explosionForce>()) { explosionForce e = rigBody.GetComponent <explosionForce>(); if (e.explodeWithExplosion) { StartCoroutine(exp(e)); } } }
IEnumerator exp(explosionForce e) { yield return(new WaitForSeconds(e.delayOfExplosionTransfer)); if (!e.hasExploded()) { e.Explode(); } }
void Start() { obj = (explosionForce)target; c = Color.red; c.a = 0.05f; }
IEnumerator exp(explosionForce e) { yield return new WaitForSeconds(e.delayOfExplosionTransfer); if (!e.hasExploded()) { e.Explode(); } }