Commit fe2a09da authored by Unknown's avatar Unknown
Browse files

Pull Baby

parent d8b09187
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using _Game.Scripts.Scriptable_Object;
public class PlayerAnimation : MonoBehaviour
{
public AnimationCurve m_AirScale;
public float m_Time = 10f;
public float m_SizePerCharge = 0.2f;
[SerializeField]
private PlayerState r_State;
[SerializeField]
private MovementController r_Controller;
private bool m_isAnimating = false;
private bool m_isScaled = false;
private int m_PreviousCharges = 0;
private MovementController r_Controller;
// Start is called before the first frame update
void Start()
......@@ -24,22 +32,43 @@ public class PlayerAnimation : MonoBehaviour
ScalePlayer();
}
public void OnChargesChange()
{
switch (r_State.GetCurrentElement())
{
case InfusedElement.None: ;
break;
case InfusedElement.Air: ;
ScalePlayer();
break;
case InfusedElement.Fire: ;
break;
case InfusedElement.Earth: ;
break;
case InfusedElement.Water: ;
break;
}
}
public void ScalePlayer()
{
if (Input.GetKeyDown(KeyCode.P) && !m_isAnimating)
int currentCharges = r_State.GetCharges();
int diff = currentCharges - m_PreviousCharges;
if (m_PreviousCharges < currentCharges && !m_isAnimating)
{
if (!m_isScaled)
{
StartCoroutine(ScaleUp(m_Time));
}
else
{
StartCoroutine(ScaleDown(m_Time));
}
//Debug.Log("Scale up");
StartCoroutine(ScaleUp(m_Time, diff));
}
else
{
Debug.Log("Scale down");
StartCoroutine(ScaleDown(m_Time, diff));
}
m_PreviousCharges = currentCharges;
}
private IEnumerator ScaleUp(float t)
private IEnumerator ScaleUp(float t, int amount)
{
m_isAnimating = true;
m_isScaled = true;
......@@ -47,16 +76,16 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / t;
for (float i = 0; i <= 1; i += step)
{
float x = m_AirScale.Evaluate(i);
float x = m_AirScale.Evaluate(i) * m_SizePerCharge * amount;
transform.localScale = s + new Vector3(x * Mathf.Sign(s.x), x, x);
r_Controller.GroundCheckDistance += x/2;
//r_Controller.GroundCheckDistance += x/2;
yield return new WaitForFixedUpdate();
}
m_isAnimating = false;
}
private IEnumerator ScaleDown(float t)
private IEnumerator ScaleDown(float t, int amount)
{
m_isAnimating = true;
m_isScaled = false;
......@@ -64,9 +93,9 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / t;
for (float i = 0; i <= 1; i += step)
{
float x = m_AirScale.Evaluate(i);
float x = m_AirScale.Evaluate(i) * m_SizePerCharge * amount;
transform.localScale = s - new Vector3(x * Mathf.Sign(s.x), x, x);
r_Controller.GroundCheckDistance -= x/2;
//r_Controller.GroundCheckDistance -= x/2;
yield return new WaitForFixedUpdate();
}
......
......@@ -44,7 +44,7 @@ namespace _Game.Scripts.Player
_earthAttack.enabled = false;
_fireAttack.enabled = false;
_waterAttack.enabled = false;
_controller.SetMovementParameters(state.GetCurrentMovementState());
//_controller.SetMovementParameters(state.GetCurrentMovementState());
}
private void Update()
......
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