75 lines
1.6 KiB
C#
75 lines
1.6 KiB
C#
using System.Linq;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
public enum TrainType
|
|
{
|
|
EP2D,
|
|
Ivolga2,
|
|
Ivolga3
|
|
}
|
|
|
|
public class LocomotionHandler : MonoBehaviour
|
|
{
|
|
[SerializeField] private Train[] trains;
|
|
|
|
public float trainSpeed;
|
|
public float pullUpPositionBefore;
|
|
public float pullUpPositionAfter;
|
|
|
|
void Update()
|
|
{
|
|
if(Input.GetKeyDown(KeyCode.Alpha1))
|
|
ShowTrain(TrainType.EP2D);
|
|
|
|
if(Input.GetKeyDown(KeyCode.Alpha2))
|
|
ShowTrain(TrainType.Ivolga2);
|
|
|
|
if(Input.GetKeyDown(KeyCode.Alpha3))
|
|
ShowTrain(TrainType.Ivolga3);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
foreach(var train in trains)
|
|
{
|
|
train.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void ShowTrain(TrainType trainType)
|
|
{
|
|
var activeTrain = trains.FirstOrDefault(x => x.gameObject.activeSelf);
|
|
if(activeTrain != null)
|
|
activeTrain.Hide();
|
|
|
|
if(!trains[0].useEffect)
|
|
{
|
|
trains.First(x => x.type == trainType)
|
|
.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
if(activeTrain != null)
|
|
StartCoroutine(WaitingTrainRoutine(trainType));
|
|
else
|
|
{
|
|
trains.First(x => x.type == trainType)
|
|
.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator WaitingTrainRoutine(TrainType trainType)
|
|
{
|
|
yield return new WaitForSeconds(3);
|
|
|
|
trains.First(x => x.type == trainType)
|
|
.gameObject.SetActive(true);
|
|
|
|
yield break;
|
|
}
|
|
} |