Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Moviment : MonoBehaviour {
- public bool teste;
- public Vector3Int destiny;
- SpriteRenderer sprite;
- Transform jumper;
- TileLogic tileAtual;
- void Awake() {
- this.jumper = this.transform.Find("Jumper");
- this.sprite = this.transform.GetComponentInChildren<SpriteRenderer>();
- }
- // Update is called once per frame
- void Update() {
- if( teste ){
- teste = false;
- StopAllCoroutines();
- StartCoroutine( Move() );
- }
- }
- IEnumerator Move(){
- yield return null;
- TileLogic tileLogic = Board.instance.tiles[ this.destiny ];
- Vector3 startPosition = this.transform.position;
- Vector3 endPosition = tileLogic.worldPosition;
- float totalTime = 1;
- float tempTime = 0;
- if( this.tileAtual == null ){
- this.tileAtual = tileLogic;
- }
- if( this.tileAtual.floor != tileLogic.floor ){
- Debug.Log( "totalTime: " + totalTime );
- StartCoroutine( Jumper( tileLogic, totalTime ) );
- }
- while ( this.transform.position != endPosition ) {
- tempTime += Time.deltaTime;
- float porcentagem = tempTime / totalTime;
- this.transform.position = Vector3.Lerp( startPosition, endPosition, porcentagem );
- yield return null;
- }
- Debug.Log( "Order: " + tileLogic.order );
- sprite.sortingOrder = tileLogic.order;
- tileLogic.content = this.gameObject;
- }
- IEnumerator Jumper( TileLogic tileLogic, float totalTime ) {
- Vector3 halfwayPosition; // = this.jumper.localPosition;
- Vector3 startPosition = halfwayPosition = this.jumper.localPosition;
- halfwayPosition.y += 0.5f;
- float tempTime = 0;
- while ( this.jumper.localPosition != halfwayPosition ) {
- tempTime += Time.deltaTime;
- float porcentagem = tempTime / ( totalTime * 0.5f ) ;
- this.jumper.localPosition = Vector3.Lerp( startPosition, halfwayPosition, porcentagem );
- yield return null;
- }
- tempTime = 0;
- while ( this.jumper.localPosition != startPosition ) {
- tempTime += Time.deltaTime;
- float porcentagem = tempTime / ( totalTime * 0.5f ) ;
- this.jumper.localPosition = Vector3.Lerp( halfwayPosition, startPosition, porcentagem );
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement