add learning
This commit is contained in:
@@ -15,15 +15,11 @@ public enum TrainType
|
||||
public class LocomotionHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Train[] trains;
|
||||
[SerializeField] private Material[] materials;
|
||||
[SerializeField] private float effectDuration;
|
||||
|
||||
public float trainSpeed;
|
||||
public float pullUpPositionBefore;
|
||||
public float pullUpPositionAfter;
|
||||
|
||||
private Coroutine c_effect;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Alpha1))
|
||||
@@ -42,11 +38,6 @@ public class LocomotionHandler : MonoBehaviour
|
||||
{
|
||||
train.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
foreach(var material in materials)
|
||||
{
|
||||
material.SetFloat("_EffectPosition", 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowTrain(TrainType trainType)
|
||||
@@ -55,51 +46,30 @@ public class LocomotionHandler : MonoBehaviour
|
||||
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);
|
||||
}
|
||||
|
||||
// void SetEffect(bool isShow)
|
||||
// {
|
||||
// if(c_effect != null)
|
||||
// {
|
||||
// StopCoroutine(c_effect);
|
||||
// c_effect = null;
|
||||
// }
|
||||
|
||||
// c_effect = StartCoroutine(SetEffectRoutine(isShow));
|
||||
// }
|
||||
|
||||
IEnumerator SetEffectRoutine(bool isShow)
|
||||
{
|
||||
float startPosition = materials[0].GetFloat("_EffectPosition");
|
||||
float currentValue = startPosition;
|
||||
float endPosition = 0;
|
||||
|
||||
if(isShow) endPosition = 5;
|
||||
else endPosition = -5;
|
||||
|
||||
float progress = 0;
|
||||
float duration = effectDuration;;
|
||||
|
||||
while(progress < 1)
|
||||
{
|
||||
currentValue = Mathf.Lerp(startPosition, endPosition, progress);
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", currentValue);
|
||||
}
|
||||
|
||||
progress += duration * Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", endPosition);
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user