private void OnCollisionEnter2D(Collision2D collision) { WaveyThing thing = collision.collider.GetComponentInParent <WaveyThing>(); if (thing && thing.isSticky) { bool wasStuck = false; stuck = thing.Attach(gameObject); if (stuck) { if (!wasStuck) { source.PlayOneShot(stickSound); source.pitch = 1.25f; source.volume = 0.3f; } Finish.IgnoreCollision(GetComponent <Collider2D>(), false); return; } } source.pitch = 1f; source.volume = Mathf.Clamp(collision.relativeVelocity.magnitude * 0.02f, 0.08f, 0.3f); source.PlayOneShot(hitSound); }
void FireBullet(float force) { Vector2 foreceDirection = new Vector2(LeftAndRight, UpAndDown).normalized; bool shouldIgnore = Vector2.Angle(Vector2.down, foreceDirection) < 90; Finish.IgnoreCollision(bullet.GetComponent <Collider2D>(), true); bullet.GetComponent <Collider2D>().enabled = true; bullet.GetComponent <StickToPlatform>().team = team; bullet.GetComponent <Grabbable>().RestoreRigidbody(); Rigidbody2D rb = bullet.GetComponent <Rigidbody2D>(); rb.AddForce(foreceDirection * force * rb.mass); GetComponent <Movement>().enabled = true; GetComponent <Holder>().enabled = true; bullet.transform.SetParent(null); enabled = false; }