04_Unity3D的输入(Input)——移动设备方向

Input也可以获取当前移动设备的方向,不过只能获取不能使用Input修改,因为Input.deviceOrientation  属性为只读的。Unity在DeviceOrientation枚举中定义了7种方向,如下所示


Variables
UnknownThe orientation of the device cannot be determined.
PortraitThe device is in portrait mode, with the device held upright and the home button at the bottom.
PortraitUpsideDownThe device is in portrait mode but upside down, with the device held upright and the home button at the top.
LandscapeLeftThe device is in landscape mode, with the device held upright and the home button on the right side.
LandscapeRightThe device is in landscape mode, with the device held upright and the home button on the left side.
FaceUpThe device is held parallel to the ground with the screen facing upwards.
FaceDownThe device is held parallel to the ground with the screen facing downwards.
大家可以使用如下脚本测试一下:
public class mono5 : MonoBehaviour {
     void OnGUI(){
          switch(Input.deviceOrientation){
               case DeviceOrientation.FaceDown:
                    GUI.Label(new Rect(100,100,100,100),"FaceDown");
                    break;
               case DeviceOrientation.FaceUp:
                    GUI.Label(new Rect(100,100,100,100),"FaceUp");
                    break;
               case DeviceOrientation.LandscapeLeft:
                    GUI.Label(new Rect(100,100,100,100),"LandscapeLeft");
                    break;
               case DeviceOrientation.LandscapeRight:
                    GUI.Label(new Rect(100,100,100,100),"LandscapeRight");
                    break;
               case DeviceOrientation.Portrait:
                    GUI.Label(new Rect(100,100,100,100),"Portrait");
                    break;
               case DeviceOrientation.PortraitUpsideDown:
                    GUI.Label(new Rect(100,100,100,100),"PortraitUpsideDown");
                    break;
               case DeviceOrientation.Unknown:
                    GUI.Label(new Rect(100,100,100,100),"Unknown");
                    break;
          }
    }
}

图示:
PortraitPortraitUpsideDownLandscapeLeftLandscapeRight
FaceUp: 手机面朝天空;
FaceDown: 手机面朝地面;
Unknown:当前方向非以上七种 或者 无法获取设备方向。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值