samedi 27 novembre 2021

Radius expansion over time does not effect actual sphere collider

So I'm trying to increase the radius of the sphere collider based on how long the player holds the mouse button down. I've tried a few different things like moving the yield return wait for seconds .1f above the small equations as well as moving some of the if statements around. If something doesn't make sense please ask. This is not the entire script

    private bool IsCasting = false;

    private float CastSpeed = StatBase.CastSpeed; // this = 1
    private float TimeSpentCasting = 0;
    private float spellCooldown = 1f; // to let animation play out

    public SphereCollider col;

    public float MaxAOERange = StatBase.AreaOfEffect + (StatBase.AreaOfEffect * (FinalStatValues.finalIncreaseAreaOfEffect / 100));

    public float AOERangePotential = 0;

    public float ExpansionSpeed = 1;

void Start()
{
        col = GetComponentInParent<SphereCollider>();
        col.radius = 0;
}



    IEnumerator SpellCastPowerBuild()
    {
        while (Input.GetMouseButtonDown(0) && IsCasting == true && TimeSpentCasting < 
        CastSpeed)

        {
            AOERangePotential += MaxAOERange / 10;
            TimeSpentCasting += CastSpeed / 10;

            if(TimeSpentCasting >= CastSpeed)
            {
                AOERangePotential = MaxAOERange;
            }

            yield return new WaitForSeconds(.1f);
        }

        if (IsCasting == false)
        {
            PerformCast();
            yield break;
        }
    }


    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && spellCooldown == 0) // SpellCooldown is set to 0
        {                                                          for testing
            IsCasting = true;
            SpellCastPowerBuild();
        }
    }


    void PerformCast()
    {
        col.radius = AOERangePotential * ExpansionSpeed * Time.deltaTime;

        AOERangePotential = 0;
        TimeSpentCasting = 0;

        IsCasting = false;
    }

Aucun commentaire:

Enregistrer un commentaire