Example #1
0
    public void ActivarEnemigos(Collider2D collision)
    {
        mov8d = collision.GetComponent <Movimiento8D>();


        x = transform.childCount;
        //es un bucle que va decrementando la x ya que van saliendo los hijos
        //según van siendo activados y se les pasa  una referencia al jugador
        while (x > 0)
        {
            hijo      = transform.GetChild(x - 1).gameObject;
            movEnemig = hijo.GetComponent <MovEnemig>();
            bomb      = hijo.GetComponent <Bomba>();
            arquero   = hijo.GetComponent <Arquer>();
            if (movEnemig != null)
            {
                movEnemig.CogerJugador(collision.gameObject);
                movEnemig.Activar(true);
            }
            if (bomb != null)
            {
                bomb.enabled = true;
                bomb.CogerJugador(collision.gameObject);
            }
            if (arquero != null)
            {
                arquero.enabled = true;
                arquero.CogeJugador(collision.gameObject);
            }

            hijo.transform.SetParent(null);
            x = transform.childCount;
        }
    }
 void Start()
 {
     rb           = GetComponent <Rigidbody2D>();
     bossmanager  = GetComponent <BossManager>();
     mirarJugador = GetComponent <MirarJugador>();
     rbplayer     = player.GetComponent <Rigidbody2D>();
     movPlayer    = player.GetComponent <Movimiento8D>();
     anim         = GetComponent <Animator>();
 }
Example #3
0
    private void Start()
    {
        playerMovement = player.GetComponent <Movimiento8D>(); //Recibe el componente para cambiar la velocidad del jugador.
        speed          = playerMovement.velocidad;

        pSprite = player.GetComponent <SpriteRenderer>(); //Guarda el sprite y el color del jugador
        //original = pSprite.color;
        tmp    = original;                                //Nuevo color con diferente alpha
        tmp.a  = 0.5f;
        etereo = player.GetComponent <Etereo>();
    }
Example #4
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && nextHit < Time.time)
        {
            nextHit    = Time.time + hitRate; // El cooldown
            movPlayer  = GetComponentInParent <Movimiento8D>();
            guardarVel = movPlayer.GetVel();
            movPlayer.CambiaVel(guardarVel / 2);    //en el tiempo que dura el ataque el personaje va más lento


            Invoke("Ataca", 0.6f);
            Invoke("ActivaAnimacion", 0f);    //Invoca la animacion de ataque
            Invoke("ParaAnimacion", 0.9f);    //Vuelve a estar estatico
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Rigidbody2D enemy = collision.gameObject.GetComponent <Rigidbody2D>();

        if (collision.gameObject.GetComponent <Movimiento8D>() != null)
        {
            if (enemy != null)
            {
                movplayer         = enemy.GetComponent <Movimiento8D>();
                movplayer.enabled = false;
                Debug.Log("Entra personaje");
                Vector2 difference = collision.transform.position - transform.position;
                enemy.AddForce(difference.normalized * fuerza, ForceMode2D.Impulse);
                Invoke("ActivaMov8D", 2f);
                GameManager.instance.TakeDamage(damage);
            }
        }

        else if (collision.gameObject.GetComponent <MovEnemig>() != null)
        {
            if (enemy != null)
            {
                movenemig         = enemy.GetComponent <MovEnemig>();
                movenemig.enabled = false;

                Vector2 difference = collision.transform.position - transform.position;
                enemy.AddForce(difference.normalized * fuerza, ForceMode2D.Impulse);
                EnemyHealth enemyHealth = collision.GetComponent <EnemyHealth>();
                enemyHealth.TakeDamage(damage);
            }
        }

        /*
         * if (collision.gameObject.tag == "Mapa")
         * {
         *  Debug.Log("ChocaPared");
         *  if (ejeX)
         *  {
         *      dirX = dirX  * -1;
         *  }
         *
         *  else
         *      dirY = dirY  * -1;
         * }
         */
    }
    public void ActivarBoss(Collider2D collision)
    {
        mov8d = collision.GetComponent <Movimiento8D>();
        if (mov8d != null)
        {
            Debug.Log("Entro");

            //es un bucle que va decrementando la x ya que van saliendo los hijos
            boss = transform.GetChild(0).gameObject;
            if (boss != null)
            {
                bossManager = boss.GetComponent <BossManager>();
                if (bossManager != null)
                {
                    Debug.Log("Entro en el boss");
                    boss.transform.SetParent(null);
                    bossManager.enabled = true;



                    //Aquí se le pasa el jugador a todos los scripts del boss
                    embeScript = boss.GetComponent <Embestida>();
                    if (embeScript != null)
                    {
                        embeScript.CogerJugador(collision.gameObject);
                    }
                    movEneScript = boss.GetComponent <MovEnemig1>();
                    if (movEneScript != null)
                    {
                        movEneScript.CogerJugador(collision.gameObject);
                    }
                    mirarJugadorScript = boss.GetComponent <MirarJugador>();
                    if (mirarJugadorScript != null)
                    {
                        mirarJugadorScript.CogerJugador(collision.gameObject);
                    }
                    ataqueScript = boss.GetComponent <AtaqueBoss1>();
                    if (ataqueScript != null)
                    {
                        ataqueScript.CogerJugador(collision.gameObject);
                    }
                }
            }
        }
    }