Пример #1
0
    public IEnumerator ShootBallCoroutine(float timeToReachTarget, Bloc blocToShoot, List <BlocColor> weaponColors)
    {
        GameObject ball         = Instantiate(Instance.GameData.ShotPrefab, ShotSpawn.position, Quaternion.identity);
        Renderer   ballRenderer = ball.GetComponent <Renderer>();

        ballRenderer.material = GameData.GetBlocColorMaterial(CurrentWeaponColors[0]);

        float   timer         = 0f;
        float   progression   = 0f;
        Vector3 startPosition = ShotSpawn.position;

        while (timer < timeToReachTarget)
        {
            if (blocToShoot == null)
            {
                break;
            }

            timer      += Time.deltaTime;
            progression = timer / timeToReachTarget;

            ball.transform.position = Vector3.Lerp(startPosition, blocToShoot.transform.position, progression);

            float yVariation = GameData.BallTrajectory.Evaluate(progression);
            ball.transform.position += Vector3.up * yVariation;

            yield return(new WaitForSeconds(Time.deltaTime));
        }

        Destroy(ball);
        if (blocToShoot.Destructible && weaponColors.Contains(blocToShoot.Color))
        {
            List <Bloc> blocsToDestroy = Tower.GetBlocsToDestroy(blocToShoot, weaponColors);
            StartCoroutine(DestroyBlocsWithIntervalTime(GameData.TimeBetweenBlocDestruction, blocsToDestroy));
        }
    }