All the needed Code for Flip and Move.
//Track Cube Movement And Location in map By X/Z Count Movement public float FromZFront = 0f; public float ToZFront= 0f; public float FromZBack = 0f; public float ToZBack = 0f; public float FromXLeft = 0f; public float ToXLeft = 0f; public float FromXRight = 0f; public float ToXRight = 0f; public float Speed = 2; public float AnimationLocation = 0f; public float TravelTime = 0f; public bool IsMoving = false; public bool MoveForward = false; public bool MoveBack = false; public bool MoveLeft = false; public bool MoveRight = false; public Animator Animation; //public Animation Anim; public bool IsFrontBlocked = false; public bool IsLeftBlocked = false; public bool IsRightBlocked = false; public bool IsBackBlocked = false; void Start() { Animation = GetComponent<Animator>(); } void Update() { //Animation Speed Animation.SetFloat("AnimationSpeed", Speed); #region CubeMoveForward Moves Cube Forward //Move Forward Trigger if (Input.GetKeyDown(KeyCode.W) && !IsMoving && !IsFrontBlocked) { FromZFront = transform.parent.position.z; ToZFront = transform.parent.position.z + 1; IsMoving = true; MoveForward = true; Animation.Play("CubeForward", -1, AnimationLocation); } //Move Forward Execution if (MoveForward) { transform.parent.position = new Vector3(transform.parent.position.x, 0, Mathf.Lerp(FromZFront, ToZFront, TravelTime)); TravelTime += Speed * Time.deltaTime; if (TravelTime > 1.1f) { TravelTime = 0.0f; FromZFront = ToZFront++; IsMoving = false; MoveForward = false; } } #endregion #region CubeMoveBack Moves Cube Backwards //Move Forward Trigger if (Input.GetKeyDown(KeyCode.S) && !IsMoving && !IsBackBlocked) { FromZBack = transform.parent.position.z; ToZBack = transform.parent.position.z - 1; IsMoving = true; MoveBack = true; Animation.Play("CubeBack", -1, AnimationLocation); } //Move Forward Execution if (MoveBack) { transform.parent.position = new Vector3(transform.parent.position.x, 0, Mathf.Lerp(FromZBack, ToZBack, TravelTime)); TravelTime += Speed * Time.deltaTime; if (TravelTime > 1.1f) { TravelTime = 0.0f; //FromZBack = transform.parent.position.z + - 1; IsMoving = false; MoveBack = false; } } #endregion #region CubeMoveRight Moves Cube Right //Move Forward Trigger if (Input.GetKeyDown(KeyCode.D) && !IsMoving && !IsRightBlocked) { FromXRight = transform.parent.position.x; ToXRight = transform.parent.position.x + 1; IsMoving = true; MoveRight = true; Animation.Play("CubeRight", -1, AnimationLocation); } //Move Forward Execution if (MoveRight) { transform.parent.position = new Vector3(Mathf.Lerp(FromXRight, ToXRight, TravelTime), 0, transform.parent.position.z); TravelTime += Speed * Time.deltaTime; if (TravelTime > 1.1f) { TravelTime = 0.0f; FromXRight = ToXRight++; IsMoving = false; MoveRight = false; } } #endregion #region CubeMoveLeft Moves Cube Left //Move Forward Trigger if (Input.GetKeyDown(KeyCode.A) && !IsMoving && !IsLeftBlocked) { FromXLeft = transform.parent.position.x; ToXLeft = transform.parent.position.x - 1; IsMoving = true; MoveLeft = true; Animation.Play("CubeLeft", -1, AnimationLocation); } //Move Forward Execution if (MoveLeft) { transform.parent.position = new Vector3(Mathf.Lerp(FromXLeft, ToXLeft, TravelTime), 0, transform.parent.position.z); TravelTime += Speed * Time.deltaTime; if (TravelTime > 1.1f) { TravelTime = 0.0f; FromXLeft = ToXLeft++; IsMoving = false; MoveLeft = false; } } #endregion }//Update End