コード例 #1
0
    private void OnCollisionEnter2D(Collision2D col)
    {
        quienChoca = col.gameObject;
        posInicial = quienChoca.transform.position;

        if (/*col.gameObject.CompareTag("Player")&&*/ top == true)
        {
            posFinalTop = new Vector2(quienChoca.transform.position.x, Mathf.Round(quienChoca.transform.position.y + 1));
            paRiba      = true;

            sonido.SonidoMover();
        }
        if (/*col.gameObject.CompareTag("Player") &&*/ bot == true)
        {
            posFinalBot = new Vector2(quienChoca.transform.position.x, Mathf.Round(quienChoca.transform.position.y - 1));
            paBajo      = true;

            sonido.SonidoMover();
        }
        if (/*col.gameObject.CompareTag("Player") &&*/ right == true)
        {
            posFinalRight = new Vector2(Mathf.Round(quienChoca.transform.position.x + 1), quienChoca.transform.position.y);
            paDerecha     = true;

            sonido.SonidoMover();
        }
        if (/*col.gameObject.CompareTag("Player") &&*/ left == true)
        {
            posFinalLeft = new Vector2(Mathf.Round(quienChoca.transform.position.x - 1), quienChoca.transform.position.y);
            paIzquierda  = true;

            sonido.SonidoMover();
        }
    }
コード例 #2
0
 // Start is called before the first frame update
 void Start()
 {
     //Busca el gameController en la escena
     gc = GameObject.Find("GameController");
     //Sonido es un script que lleva el gameobject que posee este script
     sonido = GetComponent <SonidoFantasmas>();
     //Activa una funcion del Script "Sonido"
     sonido.SonidoMover();
 }
コード例 #3
0
    //Funcion para poder moverme
    void Mover()
    {
        //Declaramos un vector que obtenga la diferencia
        //Entre la posición donde pinchamos y dónde soltamos
        //para saber la dirección en la que irá nuestro personaje

        Vector3 dif = suelto - pincho;

        if (puedoMoverme)
        {
            //Si el valor absoluto en x es mayor que el valor absoluto en y
            //Entonces la velocidad irá en el eje x
            //dependiendo de si la dirección es positiva o negativa irá hacia arriba o hacia abajo
            if (Mathf.Abs(dif.x) > Mathf.Abs(dif.y))
            {
                if (dif.x > 0)
                {
                    rb.velocity = new Vector2(1, 0) * velocidad;
                    direccion   = rb.velocity;
                }
                else
                {
                    rb.velocity = new Vector2(-1, 0) * velocidad;
                    direccion   = rb.velocity;
                }

                puedoMoverme = false;
            }
            //Si no, la velocidad irá en el eje y
            //dependiendo de si la dirección es positiva o negativa irá hacia derecha o izquierda
            else
            {
                if (dif.y > 0)
                {
                    rb.velocity = new Vector2(0, 1) * velocidad;
                    direccion   = rb.velocity;
                }
                else
                {
                    rb.velocity = new Vector2(0, -1) * velocidad;
                    direccion   = rb.velocity;
                }

                puedoMoverme = false;
            }

            sonido.SonidoMover();
        }
    }
コード例 #4
0
    void Mover()
    {
        Vector3 dif = suelto - pincho;

        if (puedoMoverme)
        {
            if (Mathf.Abs(dif.x) > Mathf.Abs(dif.y))
            {
                if (dif.x > 0)
                {
                    rb.velocity = new Vector2(1, 0) * velocidad;
                    direccion   = Vector2.zero;
                    direccion   = rb.velocity;
                    right       = true;
                }
                else
                {
                    rb.velocity = new Vector2(-1, 0) * velocidad;
                    direccion   = Vector2.zero;
                    direccion   = rb.velocity;
                    left        = true;
                }

                puedoMoverme = false;
            }

            else
            {
                if (dif.y > 0)
                {
                    rb.velocity = new Vector2(0, 1) * velocidad;
                    direccion   = Vector2.zero;
                    direccion   = rb.velocity;
                    top         = true;
                }
                else
                {
                    rb.velocity = new Vector2(0, -1) * velocidad;
                    direccion   = Vector2.zero;
                    direccion   = rb.velocity;
                    bot         = true;
                }

                puedoMoverme = false;
            }
        }

        sonido.SonidoMover();
    }
コード例 #5
0
    void Mover()
    {
        Vector3 dif = suelto - pincho;

        if (puedoMoverme)
        {
            if (Mathf.Abs(dif.x) > Mathf.Abs(dif.y))
            {
                if (dif.x > 0)
                {
                    rb.velocity = new Vector2(1, 0) * velocidad;
                    //En cada movimiento activamos la direccion que lleve el baboso
                    dcha = true;
                }
                else
                {
                    rb.velocity = new Vector2(-1, 0) * velocidad;
                    izda        = true;
                }

                puedoMoverme = false;
            }
            else
            {
                if (dif.y > 0)
                {
                    rb.velocity = new Vector2(0, 1) * velocidad;
                    sube        = true;
                }
                else
                {
                    rb.velocity = new Vector2(0, -1) * velocidad;
                    baja        = true;
                }

                puedoMoverme = false;
            }
        }
        //Reproduce el sonido de mover
        sonido.SonidoMover();
    }
コード例 #6
0
 void Start()
 {
     sonido = GetComponent <SonidoFantasmas>();
     sonido.SonidoMover();
 }