Last active
July 1, 2018 20:05
-
-
Save walkies/2caca015f8df73b511ef6bd5ef8f96ca to your computer and use it in GitHub Desktop.
BlockyRoad Drag
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 Agent : MonoBehaviour | |
{ | |
public float Speed = 1f; | |
public Rigidbody rb1; | |
Vector3 movealt = new Vector3(Mathf.Round(-1), Mathf.Round(0), Mathf.Round(1)); | |
Vector3 move = new Vector3(Mathf.Round(0), Mathf.Round(0), Mathf.Round(1)); | |
public float height; | |
public float sideBounds; | |
public float dirMax; | |
public float dirMin; | |
public enum Orientation | |
{ | |
X, | |
Y | |
} | |
public Orientation direction; | |
void start() | |
{ | |
if (direction == Orientation.X) | |
{ | |
} | |
} | |
void Update() | |
{ | |
if (direction == Orientation.X) | |
{ | |
Vector3 clampedPosition = transform.position; | |
clampedPosition.z = Mathf.Clamp(clampedPosition.z, dirMin, dirMax); | |
clampedPosition.y = Mathf.Clamp(clampedPosition.y, height, height); | |
clampedPosition.x = Mathf.Clamp(clampedPosition.x, sideBounds, sideBounds); | |
transform.position = clampedPosition; | |
} | |
else | |
{ | |
Vector3 clampedPosition = transform.position; | |
clampedPosition.z = Mathf.Clamp(clampedPosition.z, sideBounds, sideBounds); | |
clampedPosition.y = Mathf.Clamp(clampedPosition.y, height, height); | |
clampedPosition.x = Mathf.Clamp(clampedPosition.x, dirMin, dirMax); | |
transform.position = clampedPosition; | |
} | |
RaycastHit hit; | |
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (hit.rigidbody == rb1) | |
{ | |
if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Moved)) | |
{ | |
if (direction == Orientation.X) | |
{ | |
Vector3 touchDeltaPosition = Input.GetTouch(0).deltaPosition; | |
if (touchDeltaPosition.x > 0.5) | |
{ | |
rb1.MovePosition(transform.position + move); | |
} | |
else if (touchDeltaPosition.x < 0.5) | |
{ | |
rb1.MovePosition(transform.position - move); | |
} | |
} | |
else | |
{ | |
Vector3 touchDeltaPosition = Input.GetTouch(0).deltaPosition; | |
if (touchDeltaPosition.y > 0.5) | |
{ | |
rb1.MovePosition(transform.position + movealt); | |
} | |
else if (touchDeltaPosition.y < 0.5) | |
{ | |
rb1.MovePosition(transform.position - movealt); | |
} | |
} | |
} | |
else if (Input.GetTouch(0).phase == TouchPhase.Ended) | |
{ | |
Superscript.TilEmpty++; | |
Debug.Log("Thie one elly"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment