Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(GamePiece))]
- public class MovablePiece : MonoBehaviour {
- private GamePiece piece;
- private IEnumerator moveCoroutine;
- private void Awake()
- {
- piece = GetComponent<GamePiece>();
- }
- public void Move(float time, int newX, int newY)
- {
- moveCoroutine = MoveCoroutine(time, newX, newY);
- StartCoroutine(moveCoroutine);
- }
- private IEnumerator MoveCoroutine(float time, int newX, int newY)
- {
- piece.X = newX;
- piece.Y = newY;
- Vector3 startPos = transform.position;
- Vector3 endPos = piece.GridRef.GetWorldPosition(newX, newY, Grid.Layer.NORMAL);
- for (float t = 0; t <= 1 * time; t += Time.deltaTime )
- {
- piece.transform.position = Vector3.Lerp(startPos, endPos, t / time);
- yield return 0;
- }
- piece.transform.position = endPos;
- }
- }
Add Comment
Please, Sign In to add comment