Ejemplo n.º 1
0
    protected virtual IEnumerator AnimateAttack(TowerDisplay tower)
    {
        if (tower == null || tower is Object && tower.Equals(null))
        {
            yield break;
        }
        yield return(StartCoroutine(AnimateAttack()));

        if (tower == null || tower is Object && tower.Equals(null))
        {
            yield break;
        }
        var atkPwrVal = attackPower.GetValue() * (1 + technologyManager.meleeDamageRate);

        tower.TakeDamage(atkPwrVal, this);
        if (AnimationIdleIsNotNull() && !dead)
        {
            var hitFn = animationAttack.events.FirstOrDefault(x => x.functionName == "Hit");
            if (hitFn != null)
            {
                yield return(new WaitForSeconds(animationAttack.length - hitFn.time));
            }
            animator.Play(animationIdle.name, 0);
        }
    }
Ejemplo n.º 2
0
    public virtual TowerDisplay DetectEnemyTower()
    {
        if (enemyTower == null || enemyTower is Object && enemyTower.Equals(null))
        {
            return(null);
        }
        var atkRangeVal = rangeAttack.GetValue();

        if (settings.debug)
        {
            Debug.DrawRay(transform.position, Vector3.right * (int)direction * atkRangeVal, Color.yellow);
        }
        var currentX = transform.position.x;
        var rangeX   = currentX + atkRangeVal * (int)direction;

        switch (direction)
        {
        case Direction.LeftToRight:
            return(enemyTower.transform.position.x > currentX && enemyTower.transform.position.x <= rangeX ? enemyTower : null);

        case Direction.RightToLeft:
            return(enemyTower.transform.position.x >= rangeX && enemyTower.transform.position.x < currentX ? enemyTower : null);

        default:
            return(null);
        }
    }
 protected override IEnumerator AnimateAttack(TowerDisplay tower)
 {
     if (tower == null || tower is Object && tower.Equals(null))
     {
         yield break;
     }
     if (AnimationAttackIsNotNull())
     {
         yield return(StartCoroutine(PrepareAnimateLaunch()));
     }
     // var projectileIns = Instantiate<ProjectileObject> (projectileObjectPrefab, _projectilePoint.position, Quaternion.identity);
     // projectileIns.direction = direction;
     // // t = h / (uB-uA)
     // var h = tower.transform.position.x - projectileIns.transform.position.x;
     // var u = projectileIns.initialVelocity * settings.deltaSpeed * settings.deltaMoveStep * settings.deltaProjectileMoveStep;
     // var predictedTime = h / u;
     // Destroy (projectileIns.gameObject, predictedTime);
     // yield return new WaitForSeconds (predictedTime);
     if (tower != null && tower is Object && !tower.Equals(null))
     {
         var projectileIns = Instantiate <ProjectileObject> (projectileObjectPrefab, _projectilePoint.position, Quaternion.identity);
         projectileIns.direction = direction;
         var deltaDistance = Vector3.zero;
         var stopPos       = new Vector3(transform.position.x, transform.position.y, transform.position.z);
         projectileIns.Launch(tower.transform.position, deltaDistance, stopPos, () =>
         {
             if (tower)
             {
                 var atkPwrVal = attackPower.GetValue() * (1 + technologyManager.rangeDamageRate);
                 tower.TakeDamage(atkPwrVal, this);
             }
         });
     }
     // if (AnimationIdleIsNotNull () && !dead)
     // {
     //     var launchFn = animationAttack.events.FirstOrDefault (x => x.functionName == "Launch");
     //     if (launchFn != null)
     //     {
     //         yield return new WaitForSeconds (animationAttack.length - launchFn.time);
     //     }
     //     animator.Play (animationIdle.name, 0);
     // }
 }