1、在Character Controllers中拖入 预制体First Person Controller;
2、将 FPSInputController 另存为 FPSctl ,并做一下修改:
(1)增加变量:
private float rotationY;
(2)注释掉 var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
加入:
var v = new Vector3(Input.acceleration.x, Input.acceleration.y,( 1+(Input.acceleration.z))).normalized;
labeltext.text = ("v.x " + (v.x).ToString() + "rotationY" + rotationY);
if (v.z > 0)
{
directionVector = new Vector3(v.x, 0, 1-v.z);
}
else
{
directionVector = new Vector3(0, 0,0);
}
(3)在 motor.inputMoveDirection = transform.rotation * directionVector;前一行
加入:
rotationY = rotationY + v.x;
// Apply the direction to the CharacterMotor
this.transform.eulerAngles = new Vector3(0, rotationY, 0);
发布在IOS设备上时:
即可测试,运行。