コード例 #1
0
    // Use this for initialization
    void Start()
    {
        PlayerIcon.GetComponent <SpriteRenderer>().enabled = true;
        A1.GetComponent <SpriteRenderer>().enabled         = false;
        A2.GetComponent <SpriteRenderer>().enabled         = false;
        A3.GetComponent <SpriteRenderer>().enabled         = false;
        A4.GetComponent <SpriteRenderer>().enabled         = false;
        A5.GetComponent <SpriteRenderer>().enabled         = false;
        A6.GetComponent <SpriteRenderer>().enabled         = false;
        A7.GetComponent <SpriteRenderer>().enabled         = false;
        A8.GetComponent <SpriteRenderer>().enabled         = false;
        A9.GetComponent <SpriteRenderer>().enabled         = false;
        A10.GetComponent <SpriteRenderer>().enabled        = false;
        A11.GetComponent <SpriteRenderer>().enabled        = false;
        B1.GetComponent <SpriteRenderer>().enabled         = false;
        B2.GetComponent <SpriteRenderer>().enabled         = false;
        B3.GetComponent <SpriteRenderer>().enabled         = false;
        B4.GetComponent <SpriteRenderer>().enabled         = false;
        B5.GetComponent <SpriteRenderer>().enabled         = false;
        B6.GetComponent <SpriteRenderer>().enabled         = false;
        B7.GetComponent <SpriteRenderer>().enabled         = false;
        B8.GetComponent <SpriteRenderer>().enabled         = false;
        B9.GetComponent <SpriteRenderer>().enabled         = false;
        B10.GetComponent <SpriteRenderer>().enabled        = false;
        B11.GetComponent <SpriteRenderer>().enabled        = false;
        C1.GetComponent <SpriteRenderer>().enabled         = false;
        C2.GetComponent <SpriteRenderer>().enabled         = false;
        C3.GetComponent <SpriteRenderer>().enabled         = false;
        C4.GetComponent <SpriteRenderer>().enabled         = false;
        C5.GetComponent <SpriteRenderer>().enabled         = false;
        C6.GetComponent <SpriteRenderer>().enabled         = false;
        C7.GetComponent <SpriteRenderer>().enabled         = false;
        C8.GetComponent <SpriteRenderer>().enabled         = false;
        C9.GetComponent <SpriteRenderer>().enabled         = false;
        C10.GetComponent <SpriteRenderer>().enabled        = false;
        C11.GetComponent <SpriteRenderer>().enabled        = false;
        D1.GetComponent <SpriteRenderer>().enabled         = false;
        D2.GetComponent <SpriteRenderer>().enabled         = false;
        D3.GetComponent <SpriteRenderer>().enabled         = false;
        D4.GetComponent <SpriteRenderer>().enabled         = false;
        D5.GetComponent <SpriteRenderer>().enabled         = false;
        D6.GetComponent <SpriteRenderer>().enabled         = false;
        D7.GetComponent <SpriteRenderer>().enabled         = false;
        D8.GetComponent <SpriteRenderer>().enabled         = false;
        D9.GetComponent <SpriteRenderer>().enabled         = false;
        D10.GetComponent <SpriteRenderer>().enabled        = false;
        D11.GetComponent <SpriteRenderer>().enabled        = false;
        E1.GetComponent <SpriteRenderer>().enabled         = false;
        E2.GetComponent <SpriteRenderer>().enabled         = false;
        E3.GetComponent <SpriteRenderer>().enabled         = false;
        E4.GetComponent <SpriteRenderer>().enabled         = false;
        E5.GetComponent <SpriteRenderer>().enabled         = false;
        E6.GetComponent <SpriteRenderer>().enabled         = false;
        E7.GetComponent <SpriteRenderer>().enabled         = false;
        E8.GetComponent <SpriteRenderer>().enabled         = false;
        E9.GetComponent <SpriteRenderer>().enabled         = false;
        E10.GetComponent <SpriteRenderer>().enabled        = false;
        E11.GetComponent <SpriteRenderer>().enabled        = false;
        F1.GetComponent <SpriteRenderer>().enabled         = false;
        F2.GetComponent <SpriteRenderer>().enabled         = false;
        F3.GetComponent <SpriteRenderer>().enabled         = false;
        F4.GetComponent <SpriteRenderer>().enabled         = false;
        F5.GetComponent <SpriteRenderer>().enabled         = false;
        F6.GetComponent <SpriteRenderer>().enabled         = false;
        F7.GetComponent <SpriteRenderer>().enabled         = false;
        F8.GetComponent <SpriteRenderer>().enabled         = false;
        F9.GetComponent <SpriteRenderer>().enabled         = false;
        F10.GetComponent <SpriteRenderer>().enabled        = false;
        F11.GetComponent <SpriteRenderer>().enabled        = false;
        G1.GetComponent <SpriteRenderer>().enabled         = false;
        G2.GetComponent <SpriteRenderer>().enabled         = false;
        G3.GetComponent <SpriteRenderer>().enabled         = false;
        G4.GetComponent <SpriteRenderer>().enabled         = false;
        G5.GetComponent <SpriteRenderer>().enabled         = false;
        G6.GetComponent <SpriteRenderer>().enabled         = false;
        G7.GetComponent <SpriteRenderer>().enabled         = false;
        G8.GetComponent <SpriteRenderer>().enabled         = false;
        G9.GetComponent <SpriteRenderer>().enabled         = false;
        G10.GetComponent <SpriteRenderer>().enabled        = false;
        G11.GetComponent <SpriteRenderer>().enabled        = false;
        H1.GetComponent <SpriteRenderer>().enabled         = false;
        H2.GetComponent <SpriteRenderer>().enabled         = false;
        H3.GetComponent <SpriteRenderer>().enabled         = false;
        H4.GetComponent <SpriteRenderer>().enabled         = false;
        H5.GetComponent <SpriteRenderer>().enabled         = false;
        H6.GetComponent <SpriteRenderer>().enabled         = false;
        H7.GetComponent <SpriteRenderer>().enabled         = false;
        H8.GetComponent <SpriteRenderer>().enabled         = false;
        H9.GetComponent <SpriteRenderer>().enabled         = false;
        H10.GetComponent <SpriteRenderer>().enabled        = false;
        H11.GetComponent <SpriteRenderer>().enabled        = false;
        I1.GetComponent <SpriteRenderer>().enabled         = false;
        I2.GetComponent <SpriteRenderer>().enabled         = false;
        I3.GetComponent <SpriteRenderer>().enabled         = false;
        I4.GetComponent <SpriteRenderer>().enabled         = false;
        I5.GetComponent <SpriteRenderer>().enabled         = false;
        I6.GetComponent <SpriteRenderer>().enabled         = false;
        I7.GetComponent <SpriteRenderer>().enabled         = false;
        I8.GetComponent <SpriteRenderer>().enabled         = false;
        I9.GetComponent <SpriteRenderer>().enabled         = false;
        I10.GetComponent <SpriteRenderer>().enabled        = false;
        I11.GetComponent <SpriteRenderer>().enabled        = false;
        J1.GetComponent <SpriteRenderer>().enabled         = false;
        J2.GetComponent <SpriteRenderer>().enabled         = false;
        J3.GetComponent <SpriteRenderer>().enabled         = false;
        J4.GetComponent <SpriteRenderer>().enabled         = false;
        J5.GetComponent <SpriteRenderer>().enabled         = false;
        J6.GetComponent <SpriteRenderer>().enabled         = false;
        J7.GetComponent <SpriteRenderer>().enabled         = false;
        J8.GetComponent <SpriteRenderer>().enabled         = false;
        J9.GetComponent <SpriteRenderer>().enabled         = false;
        J10.GetComponent <SpriteRenderer>().enabled        = false;
        J11.GetComponent <SpriteRenderer>().enabled        = false;
        K1.GetComponent <SpriteRenderer>().enabled         = false;
        K2.GetComponent <SpriteRenderer>().enabled         = false;
        K3.GetComponent <SpriteRenderer>().enabled         = false;
        K4.GetComponent <SpriteRenderer>().enabled         = false;
        K5.GetComponent <SpriteRenderer>().enabled         = false;
        K6.GetComponent <SpriteRenderer>().enabled         = false;
        K7.GetComponent <SpriteRenderer>().enabled         = false;
        K8.GetComponent <SpriteRenderer>().enabled         = false;
        K9.GetComponent <SpriteRenderer>().enabled         = false;
        K10.GetComponent <SpriteRenderer>().enabled        = false;
        K11.GetComponent <SpriteRenderer>().enabled        = false;
        float ratio = Screen.width / Screen.height;

        if (ratio < 2)
        {
            int screenx = 543;
            int screeny = 653;
        }
        else
        {
            int screenx = 743;
            int screeny = 853;
        }
    }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        posicion = gameObject.GetComponent <Transform>().position;
        radio2   = gameObject.GetComponent <Colision_pared>().Radio;

        w1  = H1.GetComponent <T1>().w;
        mw1 = w1.magnitude;

        w2  = H2.GetComponent <T2>().w;
        mw2 = w2.magnitude;

        w3  = H3.GetComponent <T3>().w;
        mw3 = w3.magnitude;

        w4  = H4.GetComponent <T4>().w;
        mw4 = w4.magnitude;

        if (encendido == 0)
        {
            FN.y = masa * g;
            FD.y = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));

            FT       = FN - FD;
            ac       = FT / masa;
            v.x      = 0;
            v.z      = 0;
            posicion = gameObject.GetComponent <Transform>().position;
            if ((posicion.y - (radio2 - 5)) <= 0 && (v.y <= 0))
            {
                v.y = -0.3f * v.y;
            }
            else
            {
                v = v + ac * tiempo;
            }
            posicion = posicion + v * tiempo;
            gameObject.GetComponent <Transform>().position = posicion;
        }
        else
        {
            if (q)
            {
                mw1      = mw2 = mw3 = mw4;
                b        = 0.3f;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y     = masa * g;
                FD.y     = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT       = torque + FN + FD;
                ac       = FT / masa;
                ac.z     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }

            if (e)
            {
                b        = 0.03f;
                mw1      = mw3 = mw2 + 1;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y = masa * g;
                FD.y = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT   = torque + FN + FD;
                ac   = FT / masa;

                ac.z     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }

            if (a)
            {
                b        = 0.03f;
                mw1      = mw3 + 1;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y     = masa * g;
                FD.y     = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT       = torque + FN + FD;
                ac       = FT / masa;
                ac.y     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }

            if (d)
            {
                b        = 0.03f;
                mw3      = mw1 + 1;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y     = masa * g;
                FD.y     = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT       = torque + FN + FD;
                ac       = FT / masa;
                ac.y     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }

            if (w)
            {
                b        = 0.03f;
                mw4      = mw2 + 1;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y     = masa * g;
                FD.y     = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT       = torque + FN + FD;
                ac       = FT / masa;
                ac.y     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }


            if (s)
            {
                b        = 0.03f;
                mw2      = mw4 + 1;
                torque.x = L * k * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw3, 2));
                torque.z = L * k * (Mathf.Pow(mw2, 2) - Mathf.Pow(mw4, 2));
                torque.y = b * (Mathf.Pow(mw1, 2) - Mathf.Pow(mw2, 2) + Mathf.Pow(mw3, 2) - Mathf.Pow(mw4, 2));

                FN.y     = masa * g;
                FD.y     = 0.5f * (Paire * b * Area * Mathf.Pow(radio, 2));
                FT       = torque + FN + FD;
                ac       = FT / masa;
                ac.y     = 0;
                v        = v + ac * tiempo;
                posicion = posicion + v * tiempo;
            }

            if (reset)
            {
                ac.x     = ac.y = ac.z = 0;
                torque.x = torque.y = torque.z = 0;
                v.x      = v.y = v.z = 0;
                FN.y     = FN.x = FN.z = 0;
                FD.y     = FD.x = FD.z = 0;
                FT.y     = FT.x = FT.z = 0;
            }
        }

        gameObject.GetComponent <Transform>().position = posicion;
    }
コード例 #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        velocidad.text = gameObject.GetComponent <Total>().v.magnitude.ToString();
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (prendido == 0)
            {
                motor.text = "encendido";
                prendido   = 1;
                H1.GetComponent <T1>().encendido            = prendido;
                H2.GetComponent <T2>().encendido            = prendido;
                H3.GetComponent <T3>().encendido            = prendido;
                H4.GetComponent <T4>().encendido            = prendido;
                gameObject.GetComponent <Total>().encendido = prendido;

                H1.GetComponent <T1>().Fuerza.y = 10;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -10;
                H4.GetComponent <T4>().Fuerza.y = 10;
            }
            else
            {
                prendido   = 0;
                motor.text = "apagado";
                H1.GetComponent <T1>().encendido            = prendido;
                H2.GetComponent <T2>().encendido            = prendido;
                H3.GetComponent <T3>().encendido            = prendido;
                H4.GetComponent <T4>().encendido            = prendido;
                gameObject.GetComponent <Total>().encendido = prendido;
            }
        }

        if (Input.anyKey)
        {
            switch (Input.inputString)
            {
            case "q":
                movimiento.text = "q : elevarse";
                H1.GetComponent <T1>().Fuerza.y = 10;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -10;
                H4.GetComponent <T4>().Fuerza.y = 10;

                gameObject.GetComponent <Total>().q = true;
                gameObject.GetComponent <Total>().e = false;

                gameObject.GetComponent <Total>().a = false;
                gameObject.GetComponent <Total>().d = false;

                gameObject.GetComponent <Total>().w = false;
                gameObject.GetComponent <Total>().s = false;

                gameObject.GetComponent <Total>().reset = false;

                break;


            case "e":
                movimiento.text = "e : descender";
                H1.GetComponent <T1>().Fuerza.y = 11;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -11;
                H4.GetComponent <T4>().Fuerza.y = 10;

                gameObject.GetComponent <Total>().e = true;
                gameObject.GetComponent <Total>().q = false;

                gameObject.GetComponent <Total>().a = false;
                gameObject.GetComponent <Total>().d = false;

                gameObject.GetComponent <Total>().w = false;
                gameObject.GetComponent <Total>().s = false;

                gameObject.GetComponent <Total>().reset = false;

                break;

            case "a":
                movimiento.text = "a : izquierda";
                H1.GetComponent <T1>().Fuerza.y = 11;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -10;
                H4.GetComponent <T4>().Fuerza.y = 10;

                gameObject.GetComponent <Total>().e = false;
                gameObject.GetComponent <Total>().q = false;

                gameObject.GetComponent <Total>().a = true;
                gameObject.GetComponent <Total>().d = false;

                gameObject.GetComponent <Total>().w = false;
                gameObject.GetComponent <Total>().s = false;

                gameObject.GetComponent <Total>().reset = false;

                break;

            case "d":
                movimiento.text = "d : derecha";
                H1.GetComponent <T1>().Fuerza.y = 10;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -11;
                H4.GetComponent <T4>().Fuerza.y = 10;

                gameObject.GetComponent <Total>().e = false;
                gameObject.GetComponent <Total>().q = false;

                gameObject.GetComponent <Total>().a = false;
                gameObject.GetComponent <Total>().d = true;

                gameObject.GetComponent <Total>().w = false;
                gameObject.GetComponent <Total>().s = false;

                gameObject.GetComponent <Total>().reset = false;

                break;

            case "w":
                movimiento.text = "w : adelante";
                H1.GetComponent <T1>().Fuerza.y = 10;
                H2.GetComponent <T2>().Fuerza.y = -10;
                H3.GetComponent <T3>().Fuerza.y = -10;
                H4.GetComponent <T4>().Fuerza.y = 11;

                gameObject.GetComponent <Total>().e = false;
                gameObject.GetComponent <Total>().q = false;

                gameObject.GetComponent <Total>().a = false;
                gameObject.GetComponent <Total>().d = false;

                gameObject.GetComponent <Total>().w = true;
                gameObject.GetComponent <Total>().s = false;

                gameObject.GetComponent <Total>().reset = false;

                break;

            case "s":
                movimiento.text = "s : atras";
                H1.GetComponent <T1>().Fuerza.y = 10;
                H2.GetComponent <T2>().Fuerza.y = -11;
                H3.GetComponent <T3>().Fuerza.y = -10;
                H4.GetComponent <T4>().Fuerza.y = 10;

                gameObject.GetComponent <Total>().e = false;
                gameObject.GetComponent <Total>().q = false;

                gameObject.GetComponent <Total>().a = false;
                gameObject.GetComponent <Total>().d = false;

                gameObject.GetComponent <Total>().w = false;
                gameObject.GetComponent <Total>().s = true;

                gameObject.GetComponent <Total>().reset = false;

                break;

            default:
                break;
            }
        }
        else
        {
            movimiento.text = "estático";
            H1.GetComponent <T1>().Fuerza.y = 10;
            H2.GetComponent <T2>().Fuerza.y = -10;
            H3.GetComponent <T3>().Fuerza.y = -10;
            H4.GetComponent <T4>().Fuerza.y = 10;

            gameObject.GetComponent <Total>().e = false;
            gameObject.GetComponent <Total>().q = false;

            gameObject.GetComponent <Total>().a = false;
            gameObject.GetComponent <Total>().d = false;

            gameObject.GetComponent <Total>().w     = false;
            gameObject.GetComponent <Total>().s     = false;
            gameObject.GetComponent <Total>().reset = true;
        }
    }