Unity实现在安卓手机上触屏控制转向--控制对象为飞机

	该实例是Unity实现在移动端通过触摸屏幕进行对飞机的移动和转向,用于学习Touch类的相关知识
public class AirControl:MonoBehaviour{
    private Transform m_transform;          //飞机实例
    public float speed = 500f;              //飞行速度
    private float rotationz = 0.0f;         //Z轴旋转量
    public float rotateSpeed_AxisZ=45f;     //绕Z轴旋转速度
    private Vector2 touchPosition;          //触摸点坐标
    private float screenWeight;             //屏幕宽度


	void Start () {
        m_transform = this.transform;
        this.gameObject.GetComponent<Rigidbody>().useGravity = false;   //取消重力
        screenWeight = Screen.width;        //获取屏幕宽度
	}	


	void Update () {
        //设置速度
        m_transform.Translate(new Vector3(0, 0, speed * Time.deltaTime));//设置飞机飞行速度
        m_transform.Find("propeller").transform.Rotate(new Vector3(0, 1000f * Time.deltaTime, 0));//设置螺旋桨旋转速度
        #region 控制转向
        rotationz = m_transform.eulerAngles.z;            //获取飞机对象绕Z轴的旋转量
        if (Input.touchCount > 0)   //当触摸数量大于0
        {
            for(int i=0;i<Input.touchCount;i++)
            
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值