Пример #1
0
    //======================================================================================== FIREBALL

    public IEnumerator FireBallCoroutine()
    {
        isAttacking = true;

        anim.SetTrigger("LineFireBallShrink");

        FxFireLeft.SetActive(true);
        FxFireRight.SetActive(true);

        yield return(new WaitForSeconds(4.2f));

        FxFireLeft.SetActive(false);
        FxFireRight.SetActive(false);

        Vector3 target = aimedPlayer.transform.position;

        Vector3 fireBallStartingPoint = transform.position + new Vector3(0f, 8.5f, 0f);// + 2.8f * dir;

        GameObject projectileFireBall = Instantiate(fireBallPrefab, fireBallStartingPoint, Quaternion.identity);
        FireBall   fireBall           = projectileFireBall.GetComponent <FireBall>();

        float travelTime = 0;

        if (fireBall != null)
        {
            fireBall.Init(fireBallDamage, fireBallDamageExplosion, fireBallRangeExplosion, fireBallSpeed);
            travelTime = fireBall.Launch(target + new Vector3(0f, 1.5f, 0f), fireBallStartingPoint);//offset so the fireball aims for the body of the player and not his/her feet
        }

        soundEmitter.PlaySound(1);

        //show indicator feedback
        //instanciate the fireball indicator
        GameObject fireBallIndicator = Instantiate(fireBallProjector, target + new Vector3(0f, 1.5f, 0f), Quaternion.identity) as GameObject;

        projectorList.Add(fireBallIndicator);
        fireBallProjector.transform.GetChild(0).gameObject.GetComponent <Projector>().orthographicSize = fireBallRangeExplosion * toleranceCoef;
        float timeStamp = Time.time;
        Color tempColor = Color.red;

        while (Time.time - timeStamp < travelTime)
        {
            //alpha starting from 0 finishing to 0.5
            tempColor.a = ((Time.time - timeStamp) / electricAoeTimeBetweenFeedbackAndCast) / 2;
            fireBallIndicator.transform.GetChild(0).gameObject.GetComponent <Projector>().material.color = tempColor;
            yield return(new WaitForEndOfFrame());
        }


        yield return(new WaitUntil(() => fireBall.willBeDestroyed));

        Destroy(fireBallIndicator);
        soundEmitter.PlaySound(2);

        nextAttack  = Time.time + Random.Range(minWaitTime, maxWaitTime);
        isAttacking = false;
    }