Skip to content

Instantly share code, notes, and snippets.

@Hyperparticle
Last active May 25, 2018 11:30
Show Gist options
  • Save Hyperparticle/20c0b0208565fd5faec031b8ab43d8cc to your computer and use it in GitHub Desktop.
Save Hyperparticle/20c0b0208565fd5faec031b8ab43d8cc to your computer and use it in GitHub Desktop.
Rectangle Prefab Script - Version 1
public class DrawRectangle : MonoBehaviour
{
// ...
private Rigidbody2D _rigidbody2D;
private BoxCollider2D _boxCollider2D;
private bool _simulating;
public bool SimulatingPhysics
{
get { return _simulating; }
set {
_simulating = value;
_rigidbody2D.bodyType = value ?
RigidbodyType2D.Dynamic : RigidbodyType2D.Static;
}
}
private void Awake()
{
// ...
_boxCollider2D = GetComponent<BoxCollider2D>();
_lineRenderer = GetComponent<LineRenderer>();
_rigidbody2D.useAutoMass = true;
}
public void UpdateShape(Vector2 newVertex)
{
// ...
// Update the collider
var dimensions = (_vertices[1] - _vertices[0]).Abs();
_boxCollider2D.size = dimensions;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment