private BlockMover AddBlock(GameObject prefab, GroupController group, Vector3 start, Vector3 dest, float moveDamp, Material material) { BlockMover bc = Instantiate(prefab, group.transform) .GetComponent <BlockMover>(); bc.MoveTo(start, dest, moveDamp); bc.material = material; return(bc); }
private void MoveDown(GroupController group, float depthY, float moveDaming, bool isSmooth) { Transform[] transforms = group.GetElements(); foreach (var tf in transforms) { Vector3 pos = tf.position; BlockMover blockMover = tf.GetComponent <BlockMover>(); blockMover.MoveTo(new Vector3(pos.x, pos.y - depthY, pos.z), moveDaming); blockMover.isSmooth = isSmooth; } }
private void BreakTerrain() { //isBreakingTerrain = true; CameraController.isFloating = false; const float hideFactor = 30f; const float moveDaming = 6f; MoveDown(PlayerGroup, hideFactor, moveDaming, true); MoveDown(PushableGroup, hideFactor, moveDaming, true); MoveDown(GoalGroup, hideFactor, moveDaming, true); Transform[] transforms = TerrainGroup.GetElements(); foreach (var tf in transforms) { Vector3 pos = tf.position; BlockMover blockMover = tf.GetComponent <BlockMover>(); blockMover.MoveTo(new Vector3(pos.x, pos.y - Random.Range(1f, 4f), pos.z), moveDaming); } }
private void Update() { bool isMovable = true; if (lastPushable != null) { if (!lastPushable.isArrived) { isMovable = false; } } if (blockMover.isArrived && isMovable) { float horizontal = Input.GetAxisRaw("Horizontal"); float vertical = Input.GetAxisRaw("Vertical"); if (IsPressed(horizontal + vertical)) { Vector3 movement = GetMovement(horizontal, vertical); Vector3 target = _transform.position + movement; bool isMove = false; GameManager gameManager = GameManager.instance; CoordState coordState = gameManager.GetCoordState(target); if (coordState == CoordState.kPushable || coordState == CoordState.kGoal) { Vector3 targetForPushable = target + movement; if (gameManager.GetCoordState(targetForPushable) == CoordState.kMovable) { lastPushable = gameManager.GetPushable(target); lastPushable.MoveTo(targetForPushable, moveDamping); BlockMover goal = gameManager.GetGoal(targetForPushable); if (goal) { lastPushable.material = Orange; gameManager.SetCoordState(targetForPushable, CoordState.kGoal); } else { gameManager.SetCoordState(targetForPushable, CoordState.kPushable); } isMove = true; } } else if (coordState == CoordState.kMovable) { isMove = true; } if (isMove) { blockMover.MoveTo(target, moveDamping * 0.4f); blockMover.isSmooth = false; gameManager.SetCoordState(target, CoordState.kPlayer); gameManager.SetCoordState(_transform.position, CoordState.kMovable); const float degreesXFactor = 0.5f; const float degreesZFactor = 0.5f; Quaternion destination = Quaternion.Euler(new Vector3(-movement.z * degreesXFactor, 0f, movement.x * degreesZFactor)); cameraController.rotationDestination = cameraController.rotation * destination; cameraController.rotationDamping = 3.0f; cameraController.isLookAt = false; } } } }