我想要像寺运行游戏。 我需要根据我的多少倾斜装置转动我的播放器的平台。 我想加速度计,但我不能让游戏对象倾斜。 请指导我。 谢谢
这是我的代码,我使用注释代码之前,现在我尝试使用的代码出来的意见
public class tilt : MonoBehaviour {
Vector3 dir;
float movespeed;
bool istilt;
// Use this for initialization
void Start () {
dir=Vector3.zero;
movespeed=10.0f;
istilt=true;
}
// Update is called once per frame
void FixedUpdate()
{
//dir.x=-Input.acceleration.y;
//transform.Translate(dir.x,0,0);
//transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
//Vector3 vec = Physics.gravity;
/*vec.x = -Physics.gravity.z;
vec.z = Physics.gravity.x;
vec.y = 0;
transform.rotation = Quaternion.Euler(vec);*/
/*movespeed=-Input.acceleration.y;
transform.Rotate(Vector3.up*movespeed*5.0f);
*/float zmovment = Input.GetAxis("Horizontal");//-Input.acceleration.y;
float xmovment = Input.GetAxis("Vertical");//-Input.acceleration.x;
Vector3 dir = new Vector3(xmovment,0,zmovment);
Vector3 tgravity =new Vector3(zmovment*2.0f,-15,xmovment*2.0f);
Physics.gravity= tgravity;//new Vector3(zmovment*speed,gravity,xmovment*speed);
Vector3 vec = Physics.gravity;
vec.x = -Physics.gravity.z;
vec.z = Physics.gravity.x;
vec.y = 0;
transform.rotation = Quaternion.Euler(vec);
}
}