Commit 3e099fa9 authored by Sebastian's avatar Sebastian

player scales correctly

parent 07b8f5b2
...@@ -74,6 +74,7 @@ public class PlayerAnimation : MonoBehaviour ...@@ -74,6 +74,7 @@ public class PlayerAnimation : MonoBehaviour
switch (r_State.GetCurrentElement()) switch (r_State.GetCurrentElement())
{ {
case InfusedElement.None: case InfusedElement.None:
print("RESET");
if(m_ScalingActive)ScaleReset(); if(m_ScalingActive)ScaleReset();
if (m_RotationActive) if (m_RotationActive)
...@@ -84,8 +85,12 @@ public class PlayerAnimation : MonoBehaviour ...@@ -84,8 +85,12 @@ public class PlayerAnimation : MonoBehaviour
break; break;
case InfusedElement.Air: case InfusedElement.Air:
print("AIR");
m_CurrentAirCharges = r_State.GetCharges(); m_CurrentAirCharges = r_State.GetCharges();
if (m_ScalingActive) ScalePlayer(); if (m_ScalingActive)
{
ScalePlayer();
}
/*if(m_isRotating) { /*if(m_isRotating) {
SetRotationOrbsActive(true, r_State.GetCharges()); SetRotationOrbsActive(true, r_State.GetCharges());
...@@ -147,22 +152,28 @@ public class PlayerAnimation : MonoBehaviour ...@@ -147,22 +152,28 @@ public class PlayerAnimation : MonoBehaviour
public void ScalePlayer() public void ScalePlayer()
{ {
m_CurrentAirCharges = r_State.GetCharges(); m_CurrentAirCharges = r_State.GetCharges();
int diff = m_CurrentAirCharges - m_PreviousAirCharges; var scaleFactor = 1.0f + m_CurrentAirCharges * 0.2f;
//Debug.Log("current: " + currentCharges + " previous: " + m_PreviousCharges + " difference: " + diff); var direction = Mathf.Sign(this.gameObject.transform.localScale.x);
if (!m_isAnimating || m_isAnimating) var newScale = new Vector3(direction * scaleFactor * m_OriginScale.x, scaleFactor * m_OriginScale.x, 0.0f);
{ this.gameObject.transform.localScale = newScale;
if (diff > 0)
{
StartCoroutine(ScaleUp(m_PreviousAirCharges, m_CurrentAirCharges));
}
else
{
StartCoroutine(ScaleDown(m_PreviousAirCharges, m_CurrentAirCharges));
}
}
m_PreviousAirCharges = m_CurrentAirCharges; m_PreviousAirCharges = m_CurrentAirCharges;
// m_CurrentAirCharges = r_State.GetCharges();
// int diff = m_CurrentAirCharges - m_PreviousAirCharges;
// //Debug.Log("current: " + currentCharges + " previous: " + m_PreviousCharges + " difference: " + diff);
// if (!m_isAnimating || m_isAnimating)
// {
// if (diff > 0)
// {
// StartCoroutine(ScaleUp(m_PreviousAirCharges, m_CurrentAirCharges));
// }
// else
// {
// StartCoroutine(ScaleDown(m_PreviousAirCharges, m_CurrentAirCharges));
// }
// }
//
// m_PreviousAirCharges = m_CurrentAirCharges;
} }
private void ScaleReset() private void ScaleReset()
...@@ -172,23 +183,23 @@ public class PlayerAnimation : MonoBehaviour ...@@ -172,23 +183,23 @@ public class PlayerAnimation : MonoBehaviour
transform.localScale = s; transform.localScale = s;
} }
private IEnumerator ScaleUp(float from, float to) // private IEnumerator ScaleUp(float from, float to)
{ // {
m_isAnimating = true; // m_isAnimating = true;
float newSize = m_SizePerCharge * Mathf.Abs((to - from)); // float newSize = m_SizePerCharge * Mathf.Abs((to - from));
transform.localScale += new Vector3(newSize * Mathf.Sign(transform.localScale.x), newSize, newSize); // transform.localScale += new Vector3(newSize * Mathf.Sign(transform.localScale.x), newSize, newSize);
yield return null; // yield return null;
m_isAnimating = false; // m_isAnimating = false;
} // }
//
private IEnumerator ScaleDown(float from, float to) // private IEnumerator ScaleDown(float from, float to)
{ // {
m_isAnimating = true; // m_isAnimating = true;
float newSize = m_SizePerCharge * Mathf.Abs((to - from)); // float newSize = m_SizePerCharge * Mathf.Abs((to - from));
transform.localScale -= new Vector3(newSize * Mathf.Sign(transform.localScale.x), newSize, newSize); // transform.localScale -= new Vector3(newSize * Mathf.Sign(transform.localScale.x), newSize, newSize);
yield return null; // yield return null;
m_isAnimating = false; // m_isAnimating = false;
} // }
/*private IEnumerator ScaleUp(float from, float to) /*private IEnumerator ScaleUp(float from, float to)
......
...@@ -45,6 +45,11 @@ namespace _Game.Scripts.Player ...@@ -45,6 +45,11 @@ namespace _Game.Scripts.Player
_waterAttack.enabled = false; _waterAttack.enabled = false;
} }
private void OnDisable()
{
state.UpdateElement(InfusedElement.None);
}
private void Update() private void Update()
{ {
if (Input.GetButtonDown("Fire1")) if (Input.GetButtonDown("Fire1"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment