Exemple #1
0
    public IEnumerator ShootFireballCoroutine(Vector3 startPosition, Vector3 endPosition, Action action, float speed = 20)
    {
        GameObject   fireBall       = Instantiate(FireBallPrefab, startPosition, FireBallPrefab.transform.rotation);
        ExplodeOnHit myExplodeOnHit = fireBall.gameObject.GetComponent <ExplodeOnHit>();

        // make fireball explode instantly if instantiated on the destination
        if (fireBall.transform.position == endPosition)
        {
            myExplodeOnHit.Explode();
            action.actionResolved = true;
        }

        // else, travel towards destination, explode on arrival
        while (fireBall.transform.position != endPosition)
        {
            fireBall.transform.position = Vector2.MoveTowards(fireBall.transform.position, endPosition, speed * Time.deltaTime);
            if (fireBall.transform.position == endPosition)
            {
                myExplodeOnHit.Explode();
                action.actionResolved = true;
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Exemple #2
0
    public IEnumerator ShootShadowBallCoroutine(Vector3 startPosition, Vector3 endPosition, Action action, float speed = 4)
    {
        GameObject   shadowBall     = Instantiate(ShadowBallPrefab, startPosition, ShadowBallPrefab.transform.rotation);
        ExplodeOnHit myExplodeOnHit = shadowBall.gameObject.GetComponent <ExplodeOnHit>();

        while (shadowBall.transform.position != endPosition)
        {
            shadowBall.transform.position = Vector2.MoveTowards(shadowBall.transform.position, endPosition, speed * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        if (shadowBall.transform.position == endPosition)
        {
            myExplodeOnHit.Explode();
            action.actionResolved = true;
        }
    }
Exemple #3
0
    public IEnumerator ShootFrostBoltCoroutine(Vector3 startPosition, Vector3 endPosition, Action action, float speed = 5)
    {
        GameObject frostBolt = Instantiate(FrostBoltPrefab, startPosition, FrostBoltPrefab.transform.rotation);

        FaceDestination(frostBolt, endPosition);
        ExplodeOnHit myExplodeOnHit = frostBolt.gameObject.GetComponent <ExplodeOnHit>();

        while (frostBolt.transform.position != endPosition)
        {
            frostBolt.transform.position = Vector2.MoveTowards(frostBolt.transform.position, endPosition, speed * Time.deltaTime);
            if (frostBolt.transform.position == endPosition)
            {
                myExplodeOnHit.Explode();
                action.actionResolved = true;
            }
            yield return(new WaitForEndOfFrame());
        }
    }