The use of "Little Super _u3d" Unity3d Gyro

Source: Internet
Author: User

Recently in a virtual reality project, I've been looking for a gyroscope article in unity. The following code is I find out on the Internet, when I use it can not be used. Now this is a modified one, although the copy can be used, very convenient.

The using unityengine;using system.collections;//camera Gyroscope rotates the public class iphonegyro:monobehaviour{//bool Gyrobool;    Gyroscope Gyro;    Quaternion Quatmult;    Quaternion Quatmap;    UILabel ul;   Gameobject player;    Gameobject camparent;        void Awake () {player = Gameobject.find ("player");        Find the current parent of the camera ' s transform transform currentparent = transform.parent;        Instantiate a new transform camparent = new Gameobject ("Camparent");        Match the transform to the camera position camParent.transform.position = transform.position;        Make the new transform the parent of the camera transform transform.parent = camparent.transform;        Make the original parent the grandparent of the camera transform//camparent.transform.parent = currentparent;        Instantiate a new transform gameobject camgrandparent = new Gameobject ("Camgrandparent"); Match the transform to THe camera position camGrandparent.transform.position = transform.position;         Make the new transform the parent of the camera transform camParent.transform.parent = camgrandparent.transform; Make the original parent the grandparent of the camera transform camGrandparent.transform.parent = Curre        Ntparent;        Gyrobool = true;        if (gyrobool) {gyro = Input.gyro; UL = Gameobject.find ("Rotation").        Getcomponent<uilabel> ();        Gyro.enabled = true;        CamParent.transform.eulerAngles = new Vector3 (90,0, 0);         Quatmult = new quaternion (0, 0, 1, 0); } void Update () {quatmap = new quaternion (gyro.attitude.x, Gyro.attitude.y, Gyro.attitude.z, Gyro.attitu        DE.W);               quaternion qt=quatmap * QUATMULT;                     Transform.localrotation =QT;                   Ul.text = "Rotation:" + transform.localrotation + "player" + player.transform.localRotation; }   }
Perfect running on Android


Reprint Please specify: http://blog.csdn.net/dzc372787439


The use of "Little Super _u3d" Unity3d Gyro

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.