为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

手机重力感应代码

2017-10-25 7页 doc 21KB 29阅读

用户头像

is_511210

暂无简介

举报
手机重力感应代码手机重力感应代码 //Ð?ÇòµÄÌùÍ? var round : Texture2D; //Ð?ÇòÔÚÆÁÄ?ÖÐÏÔÊ?µÄX Y×ø?ê var x = 0; var y = 0; //Ð?ÇòÆÁÄ?ÏÔÊ?µÄ×î?ó X Y ??Î? var cross_x = 0; var cross_y = 0; function Start(){ //?õÊ?????Öµ cross_x = Screen.width - round.width; cross_y = Screen.height - ...
手机重力感应代码
手机重力感应代码 //Ð?ÇòµÄÌùÍ? var round : Texture2D; //Ð?ÇòÔÚÆÁÄ?ÖÐÏÔÊ?µÄX Y×ø?ê var x = 0; var y = 0; //Ð?ÇòÆÁÄ?ÏÔÊ?µÄ×î?ó X Y ??Î? var cross_x = 0; var cross_y = 0; function Start(){ //?õÊ?????Öµ cross_x = Screen.width - round.width; cross_y = Screen.height - round.height; } function OnGUI () { //ÕûÌåÏÔÊ? x y z ÖØÁ??ÐÓ?µÄÖØÁ??ÖÁ? GUI.Label(Rect(0,0,480,100),"position is " + Input.acceleration); //?æÖÆÐ?Çò GUI.DrawTexture(Rect(x,y,256,256),round); } function Update(){ //?ù?ÝÖØÁ??ÖÁ?ÐÞ?ÄÐ?ÇòµÄÎ?ÖÃÕâÀï?ËÒÔ30µÄÒâË?ÊÇÈÃÐ?ÇòÒÆ??µÄ?ìÒ?Ð? x += Input.acceleration.x * 30; y += -Input.acceleration.y * 30; //?ÜÃâÐ?Çò???öÆÁÄ? if(x < 0){ x = 0; }else if(x > cross_x){ x = cross_x; } if(y < 0){ y = 0; }else if(y > cross_y){ y = cross_y; } } //---------------------------------------------------------------- ---------------------------------- ?ýInput.accelerationÈ?Äõ?µ?Ç?ÊÖ?úµÄÖØÁ??ÐÓ??ÖÁ? //---------------------------------------------------------------- ---------------------------------- ????Ò??ºspeed public var simulateAccelerometer:boolean = false; var speed = 10.0; function Update () { var dir : Vector3 = Vector3.zero; if (simulateAccelerometer) { dir.x = Input.GetAxis("Horizontal"); dir.y = Input.GetAxis("Vertical"); } else { dir.x = Input.acceleration.x; dir.y = Input.acceleration.y; // clamp acceleration vector to unit sphere if (dir.sqrMagnitude > 1) dir.Normalize(); // Make it move 10 meters per second instead of 10 meters per frame... } dir *= Time.deltaTime; // Move object transform.Translate (dir * speed); } Ò??ÉÒÔ?ÑËÙ?È???ÉÁ? ?????þ?ºForce public var force:float = 1.0; public var simulateAccelerometer:boolean = false; function FixedUpdate () { var dir : Vector3 = Vector3.zero; if (simulateAccelerometer) { // using joystick input instead of iPhone accelerometer dir.x = Input.GetAxis("Horizontal"); dir.y = Input.GetAxis("Vertical"); } else { // we assume that device is held parallel to the ground // and Home button is in the right hand // remap device acceleration axis to game coordinates // 1) XY plane of the device is mapped onto XZ plane // 2) rotated 90 degrees around Y axis dir.x = Input.acceleration.y; dir.y = Input.acceleration.x; // clamp acceleration vector to unit sphere if (dir.sqrMagnitude > 1) dir.Normalize(); } rigidbody.AddForce(dir * force); } //---------------------------------------------------------------- ---------------------------------- public var simulateAccelerometer:boolean = false; var speed = 10.0; function Update () { var dir : Vector3 = Vector3.zero; if (simulateAccelerometer) { dir.x = Input.GetAxis("Horizontal"); dir.y = Input.GetAxis("Vertical"); } else { dir.x = Input.acceleration.x; dir.y = Input.acceleration.y; // clamp acceleration vector to unit sphere if (dir.sqrMagnitude > 1) dir.Normalize(); // Make it move 10 meters per second instead of 10 meters per frame... } dir *= Time.deltaTime; // Move object transform.Translate (dir * speed); } ??ÖÆ?úÂë Ò??ÉÒÔ?ÑËÙ?È???ÉÁ? ?????þ?ºForce view sourceprint? public var force:float = 1.0; public var simulateAccelerometer:boolean = false; function FixedUpdate () { var dir : Vector3 = Vector3.zero; if (simulateAccelerometer) { // using joystick input instead of iPhone accelerometer dir.x = Input.GetAxis("Horizontal"); dir.y = Input.GetAxis("Vertical"); } else { // we assume that device is held parallel to the ground // and Home button is in the right hand // remap device acceleration axis to game coordinates // 1) XY plane of the device is mapped onto XZ plane // 2) rotated 90 degrees around Y axis dir.x = Input.acceleration.y; dir.y = Input.acceleration.x; // clamp acceleration vector to unit sphere if (dir.sqrMagnitude > 1) dir.Normalize(); } rigidbody.AddForce(dir * force); } ??ÖÆ?úÂë ?öÈË?Ð?õ????Ò??Ù?ØÆðÀ??È?ÏÁé?î????Ó?ÁéÃô???????þ?Ù?ØÆðÀ??ßÓÐ?ßÐÔ???º?åÃ?ÏÔ?? //-------------------------------------------------------------------------------------------------- virtual
/
本文档为【手机重力感应代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索