public void SetDirection(Direction direction) { if (_canTurn == false) { return; } switch (direction) { case Direction.RIGHT: { _moveDirection = OnCameraRequest.Invoke(CameraController.RotateAxis.FORWARD, -90.0f); _canTurn = false; break; } case Direction.LEFT: { _moveDirection = OnCameraRequest.Invoke(CameraController.RotateAxis.FORWARD, 90.0f); _canTurn = false; break; } } }
private void Move() { if (Mathf.RoundToInt(Vector3.Dot(_snake[0].position, _moveDirection)) == _gridSize) { _moveDirection = OnCameraRequest.Invoke(CameraController.RotateAxis.RIGHT, 90.0f); } _canTurn = true; Vector3 newPos = _snake[0].position + _moveDirection; for (int i = _snake.Count - 1; i >= 1; --i) { _snake[i].position = _snake[i - 1].position; if (Vector3Int.RoundToInt(_snake[i].position) == Vector3Int.RoundToInt(newPos)) { _isDead = true; _canTurn = false; } } _snake[0].position = newPos; }