venerdì 27 aprile 2018

Daydream Controller in Unity

Un semplice esempio di script da aggiungere al Player per muovere la Camera di Unity con il DayDream Controller





public class move_player : MonoBehaviour {


    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        Quaternion ori;

        ori = GvrController.Orientation;
        if (ori.eulerAngles.z > 20 && ori.eulerAngles.z < 90) {
            Debug.Log ("Roll Left ");
        }

        if (ori.eulerAngles.z > 270 && ori.eulerAngles.z < 340) {
            Debug.Log ("Roll Right");
        }

        if (ori.eulerAngles.x > 20 && ori.eulerAngles.x < 90) {
            Debug.Log ("Drop");
            var rot = transform.rotation;
            rot.z -= Time.deltaTime * 1;
            transform.rotation = rot;
        }

        if (ori.eulerAngles.x > 270 && ori.eulerAngles.x < 340) {
            Debug.Log ("Climb");
            var rot = transform.rotation;
            rot.z += Time.deltaTime * 1;
            transform.rotation = rot;

        }





        Debug.Log ("X : " + ori.eulerAngles.x.ToString("#.0")); //pitch
        Debug.Log ("Y : " + ori.eulerAngles.y.ToString("#.0")); // yaw
        Debug.Log ("Z : " + ori.eulerAngles.z.ToString("#.0")); // roll



        if (GvrController.IsTouching) {
            Vector2 touchPos = GvrController.TouchPos;
            Debug.Log ("Toccato " + touchPos.x.ToString ("#.00"));

            var x = touchPos.x * Time.deltaTime * 5.0f;
            var y = touchPos.y * Time.deltaTime * 5.0f;
            if (touchPos.x < 0.5f)
                x *= -1.0f;
            else
                x *= +1.0f;
            
            if (touchPos.y < 0.5f)
                y *= -1.0f;
            else
                y *= +1.0f;

            transform.Translate (x, y, 0.0f);
        }
        
    }
}

Nessun commento:

Posta un commento

Perche' investire su Unix

 Un libro trovato nel libero scambio alla Coop su cio' che poteva essere e non e' stato...interessante la storia su Unix del primo c...