Sådan her ser koden ud
Code: Select all
int layerID = LayerMask.NameToLayer("Platform");
if (!Physics.Raycast(transform.position, -Vector3.up, 0.8f) || !Physics.Raycast(transform.position, Vector3.forward, 0.8f, layerID))
{
switch (state)
{
case State.Left:
state = State.Right;
break;
case State.Right:
state = State.Left;
break;
}
}
if (state == State.Right)
{
transform.Translate(Vector3.right * amtToMove);
}
else if (state == State.Left)
{
transform.Translate(Vector3.left * amtToMove);
}