public bool moveCheck(Vector3 direction) { RaycastHit hitInfo; bool canMove = false; if (Physics.Raycast(transform.position, direction, out hitInfo, 1f, rayMask)) { if (hitInfo.transform.gameObject.CompareTag("Player")) // If the space it's moving to is occupied by another slider, checks to see if that slider is able to move { bool nextIsMoveable = hitInfo.transform.GetComponent <MoveableObject>().moveCheck(direction); if (nextIsMoveable) { flag = checkFlag.MOVEABLE; canMove = true; } else { flag = checkFlag.UNMOVEABLE; canMove = false; } } else { flag = checkFlag.UNMOVEABLE; canMove = false; } } else { flag = checkFlag.MOVEABLE; canMove = true; } return(canMove); }
IEnumerator movePrevious() { while (transform.position != previousPosition) { transform.position = Vector3.MoveTowards(transform.position, previousPosition, moveSpeed * Time.deltaTime); yield return(null); } previousPosition = transform.position; flag = checkFlag.UNCHECKED; _manager.finishMoving(); }
void moveObject(Vector3 direction) { if (flag == checkFlag.MOVEABLE) { StartCoroutine(move(direction)); } else { flag = checkFlag.UNCHECKED; _manager.finishMoving(); } }
public IEnumerator move(Vector3 direction) { nextDirection = direction; // used to account for special events that move the slider an additional space. while (nextDirection != Vector3.zero) { Vector3 targetPos = transform.position + nextDirection; nextDirection = Vector3.zero; while (transform.position != targetPos) { transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime); yield return(null); } previousPosition = transform.position; } flag = checkFlag.UNCHECKED; _manager.finishMoving(); }
public void resetPosition() { StopAllCoroutines(); flag = checkFlag.UNCHECKED; transform.position = originalPosition; }