Last active
July 14, 2016 17:49
-
-
Save piedoom/828fef9f8662c8ac62c8ba3c7295e916 to your computer and use it in GitHub Desktop.
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
class TestCollider : Component, IUpdatable | |
{ | |
public float Distance; | |
public override void onAddedToEntity() | |
{ | |
entity.addCollider<BoxCollider>(new BoxCollider(100,100)); | |
} | |
public void update() | |
{ | |
var bottomLeft = new Vector2(entity.colliders.First().bounds.left, entity.colliders.First().bounds.bottom);; | |
RaycastHit bottomHit = Physics.linecast(bottomLeft, bottomLeft + (Vector2.UnitY * 100)); | |
Debug.drawLine(bottomLeft, bottomLeft + (Vector2.UnitY * 100), Color.Red); | |
if (bottomHit.collider != null) | |
Distance = bottomHit.distance; | |
var position = Input.mousePosition; | |
if (Input.leftMouseButtonDown) | |
transform.position = position; | |
} | |
} | |
// in the scene file | |
public override void onStart() | |
{ | |
createEntity("tracker").addComponent<TestCollider>(new TestCollider()); | |
createEntity("circle", new Vector2(800, 200)).addCollider<CircleCollider>(new CircleCollider(50)); | |
createEntity("box", new Vector2(500, 300)).addCollider<BoxCollider>(new BoxCollider(50,50)); | |
createEntity("polygon", new Vector2(600, 300)).addCollider<PolygonCollider>(new PolygonCollider(new Vector2[] { new Vector2(0,50), new Vector2(100, 0), new Vector2(100, 100), new Vector2(0, 100)})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment