IEnumerable pewpew(Vector2 direction)
    {
        //   Debug.Log("ooga");
        RaycastHit2D fire = Physics2D.Raycast(shootingPoint.position, direction, 6f, shoot);

        if (fire)
        {
            EnemyFly enemy = fire.transform.GetComponent <EnemyFly>();
            enemy.loseHP();

            lineRenderer.SetPosition(0, shootingPoint.position);
            lineRenderer.SetPosition(1, fire.point);
        }
        else
        {
            lineRenderer.SetPosition(0, shootingPoint.position);
            lineRenderer.SetPosition(1, shootingPoint.position + shootingPoint.up * 200);
        }

        lineRenderer.enabled = true;

        //  wait one frame
        yield return(new WaitForSeconds(coolDownPeriodInSeconds));

        lineRenderer.enabled = false;
    }
Exemple #2
0
 protected virtual void Awake()
 {
     body2d         = GetComponent <Rigidbody2D>();
     collisionState = GetComponent <CollisionState>();
     enemyDeath     = GetComponent <EnemyDeath>();
     enemyFly       = GetComponent <EnemyFly>();
     moveForward    = GetComponent <MoveForward>();
     enemyReady     = GetComponent <EnemyReady>();
     playerInRange  = false;
     player         = GameObject.Find("Player");
 }
Exemple #3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (!isInvincible)
     {
         EnemyPatrol _enemyPatrol = collision.collider.GetComponent <EnemyPatrol>();
         if (_enemyPatrol != null)
         {
             foreach (ContactPoint2D point in collision.contacts)
             {
                 if (point.normal.y >= 0.9f)
                 {
                     //Vector2 velocity = playerBody.velocity;
                     //velocity = jumpVelocity*Vector2.up;
                     //playerBody.velocity = velocity;
                     _enemyPatrol.KillEnemy();
                 }
                 else
                 {
                     DamagePlayer(_enemyPatrol.enemyStats.damage);
                     StartCoroutine("BeInvincible");
                 }
             }
         }
         EnemyFly _enemyFly = collision.collider.GetComponent <EnemyFly>();
         if (_enemyFly != null)
         {
             foreach (ContactPoint2D point in collision.contacts)
             {
                 if (point.normal.y >= 0.9f)
                 {
                     //Vector2 velocity = playerBody.velocity;
                     //velocity = jumpVelocity*Vector2.up;
                     //playerBody.velocity = velocity;
                     _enemyFly.KillEnemy();
                 }
                 else
                 {
                     DamagePlayer(_enemyFly.enemyStats.damage);
                     StartCoroutine("BeInvincible");
                 }
             }
         }
     }
 }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (isPatrol)
     {
         EnemyPatrol2 enemy = collision.GetComponent <EnemyPatrol2>();
         if (enemy != null)
         {
             enemy.BackFlip();
         }
     }
     else
     {
         EnemyFly enemy = collision.GetComponent <EnemyFly>();
         if (enemy != null)
         {
             enemy.BackFlip();
         }
     }
 }
    void Awake()
    {
        for (int i = 0; i < transform.childCount; i++)       //conta y agrega a la lista, pero solo si el objeto esta activo.
        {
            if (transform.GetChild(i).gameObject.activeSelf) //si el hijo esta activo
            {
                gameManager.addOneInEnemyCounter();          //Agregalo al contador de enemigos

                //y acá se setean los gameManagers y players.
                EnemyController enemyController = transform.GetChild(i).gameObject.GetComponent <EnemyController>();
                enemyController.SetPlayer(player);
                enemyController.SetGameManager(gameManager);

                LifeController life = transform.GetChild(i).gameObject.GetComponent <LifeController>();
                life.SetGameManager(gameManager);


                //y dependiendo del tipo de controller que tenga, se le setea la data.
                EnemyStaticController enemyStatic = transform.GetChild(i).gameObject.GetComponent <EnemyStaticController>();
                if (enemyStatic != null)
                {
                    enemyStatic.SetPlayer(player);
                    enemyStatic.SetGameManager(gameManager);
                }

                EnemyFly enemyFly = transform.GetChild(i).gameObject.GetComponent <EnemyFly>();
                if (enemyFly != null)
                {
                    enemyFly.SetPlayer(player);
                    enemyFly.SetGameManager(gameManager);
                }

                EnemyPatrol2 enemyPatrol = transform.GetChild(i).gameObject.GetComponent <EnemyPatrol2>();
                if (enemyPatrol != null)
                {
                    enemyPatrol.SetGameManager(gameManager);
                }
            }
        }
    }
 void Start()
 {
     audio = GetComponent <AudioSource>();
     fly   = GetComponent <EnemyFly>();
 }