- Home /
Question by
mossbeard1 · Oct 16, 2018 at 04:32 AM ·
timelerpswitchmathfmathf.lerp
Trying to lerp in different states in a switch statement
So I'm trying to smoothly lerp one of my image.fillamount to a certain decimal each state swap but seem to only get it to work on the first state but not the others. you'll notice a commented out coroutine I tried using it as a method before I tried using a coroutine and had troubles with increasing time. so if you can tell me how to increase time in a separate method that would solve my problem as well!
public Image PowerBG;
public Image PowerPNG;
public Image _NulledOut;
//public float Dampening;
//private float SpeedVal;
private float waitTime = 15f;
private bool IsLost;
//private float PrevAmount;
private float temp;
[Range(0,5)]
private int FailedCount = 0;
[HideInInspector]
public int StreakCount = 0;
public static Power instance = null;
private void Awake()
{
if(instance == null)
{
instance = this;
}
else if(instance != this)
{
Destroy(this.gameObject);
}
temp = .15f;
FailedCount = 0;
StreakCount = 0;
PowerPNG.fillAmount = 1f;
StartCoroutine(HasPower(IsLost));
Core.failed += Failure;
Core.Success += Streak;
}
public void PowerClick()
{
PowerPNG.fillAmount += .1f;
}
IEnumerator HasPower(bool _IsLost)
{
//MyMono myMonoo = new Core();
// Core myCorez = (Core)myMonoo;
while (!_IsLost)
{
PowerPNG.fillAmount -= 1.0f / waitTime * Time.deltaTime;
if(PowerPNG.fillAmount == 0.0f)
{
_IsLost = true;
}
switch (FailedCount)
{
case 0:
_NulledOut.gameObject.SetActive(false);
PowerPNG.fillAmount = Mathf.Clamp(PowerPNG.fillAmount, 0, 1f);
break;
case 1:
//FailState(PowerPNG, _NulledOut, temp * Time.deltaTime, 0, .2f, 1, 1);
temp += .15f * Time.deltaTime;
_NulledOut.fillAmount = Mathf.Lerp(0, .2f, temp);
_NulledOut.AlphaPingPong();
PowerPNG.fillAmount = Mathf.Clamp(PowerPNG.fillAmount, 0, 1 - _NulledOut.fillAmount);
break;
case 2:
// FailState(PowerPNG, _NulledOut, temp * Time.deltaTime, .2f, .4f,2,2);
//float Ttemp = 0;
temp = 1f;
temp += .15f * Time.deltaTime;
_NulledOut.fillAmount = Mathf.Lerp(.2f, .4f, temp);
_NulledOut.AlphaPingPong();
PowerPNG.fillAmount = Mathf.Clamp(PowerPNG.fillAmount, 0, 1 - _NulledOut.fillAmount);
break;
case 3:
//temp = 0f;
//float TTtemp = 0;
temp += .15f * Time.deltaTime;
_NulledOut.fillAmount = Mathf.Lerp(.4f, .6f, temp);
_NulledOut.AlphaPingPong();
PowerPNG.fillAmount = Mathf.Clamp(PowerPNG.fillAmount, 0, 1 - _NulledOut.fillAmount);
break;
case 4:
//float TTTtemp = 0;
temp += .15f * Time.deltaTime;
_NulledOut.fillAmount = Mathf.Lerp(.6f, .8f, temp);
_NulledOut.AlphaPingPong();
PowerPNG.fillAmount = Mathf.Clamp(PowerPNG.fillAmount, 0, 1 - _NulledOut.fillAmount);
break;
default:
_NulledOut.fillAmount = Mathf.Lerp(.8f, 1f, temp);
_IsLost = true;
break;
}
yield return null;
}
SceneManager.LoadScene(0);
}
//IEnumerator FailState(Image _Power, Image _Nulled, float _Temp, float _NullStart, float _NullGoal, int _currentNum, int _state)
//{
// _Temp = 0;
// while(_currentNum == _state)
// {
// _Temp += .15f * Time.deltaTime;
// _Nulled.fillAmount = Mathf.Lerp(_NullStart, _NullGoal, _Temp);
// if(_Nulled.fillAmount == _NullGoal)
// {
// }
// _Nulled.AlphaPingPong();
// _Power.fillAmount = Mathf.Clamp(_Power.fillAmount, 0, 1 - _Nulled.fillAmount);
// yield return null;
// }
//}
void Failure()
{
_NulledOut.gameObject.SetActive(true);
FailedCount++;
StreakCount = 0;
}
void Streak()
{
StreakCount++;
if(StreakCount % 4 == 0 && FailedCount > 0)
{
FailedCount--;
Debug.Log("reducestate");
}
Debug.Log("success");
}
Comment
Your answer
Follow this Question
Related Questions
how to use time on lerp 2 Answers
Jump with mathf.lerp problem 2 Answers
How the heck does Mathf.Lerp work? 2 Answers
Making an object bounce, using Mathf.Lerp 1 Answer
Mathf.Lerp happens instantly 2 Answers