public static void SetPaused(Rigidbody2D rb, bool paused) { Rigidbody2D_ex ex = rb.gameObject.GetComponent <Rigidbody2D_ex>(); if (!ex) { ex = rb.gameObject.AddComponent <Rigidbody2D_ex>(); } ex.SetPaused(paused); }
public static void SetEnabled(GameObject go, bool enabled) { foreach (PausableRepetition script in go.GetComponentsInChildren <PausableRepetition>()) { script.enabled = enabled; } foreach (Pausable script in go.GetComponentsInChildren <Pausable>()) { script.enabled = enabled; } foreach (Rigidbody2D rigidbody in go.GetComponentsInChildren <Rigidbody2D>()) { Rigidbody2D_ex.SetPaused(rigidbody, !enabled); } }
protected virtual void Shot() { if (bulletTemplate == null) { return; } GameObject newBullet = (GameObject)Instantiate(bulletTemplate); Utils.AssignTransformFromTo(this.gameObject.transform, newBullet.transform); Rigidbody2D rb2D = newBullet.GetComponent <Rigidbody2D> (); Vector2 newBulletVelocity = this.gameObject.transform.up * bulletSpeed; Rigidbody2D_ex.SetScaledVelocity(rb2D, newBulletVelocity); AddComponentsToBullet(newBullet); }
protected void Move(Vector2 movement) { Rigidbody2D rb2D = this.gameObject.GetComponent <Rigidbody2D> (); if (rb2D == null) { return; } float movementMultiplifier = Speed * GetModifierValue(ShipModifierType.smtMoveSpeed); Rigidbody2D_ex.SetScaledVelocity(rb2D, movement * movementMultiplifier); rb2D.position = new Vector2( Mathf.Clamp(rb2D.position.x, zone.xMin, zone.xMax), Mathf.Clamp(rb2D.position.y, zone.yMin, zone.yMax) ); }