Last active
May 25, 2018 11:30
-
-
Save Hyperparticle/20c0b0208565fd5faec031b8ab43d8cc to your computer and use it in GitHub Desktop.
Rectangle Prefab Script - Version 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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