add train moving logic
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
public class Train : MonoBehaviour
|
||||
{
|
||||
public TrainType type;
|
||||
private LocomotionHandler locomotionHandler;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(locomotionHandler == null)
|
||||
locomotionHandler = FindObjectOfType<LocomotionHandler>();
|
||||
|
||||
var startPosition = locomotionHandler.pullUpPositionBefore;
|
||||
var speed = locomotionHandler.trainSpeed;
|
||||
|
||||
transform.localPosition = new Vector3(transform.localPosition.x,
|
||||
transform.localPosition.y,
|
||||
startPosition);
|
||||
|
||||
transform.DOLocalMoveZ(0, speed)
|
||||
.SetEase(Ease.OutSine);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
var endPosition = locomotionHandler.pullUpPositionAfter;
|
||||
var speed = locomotionHandler.trainSpeed;
|
||||
|
||||
transform.DOLocalMoveZ(endPosition, speed)
|
||||
.SetEase(Ease.InSine)
|
||||
.OnComplete(() => gameObject.SetActive(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user