1. 程式人生 > >u3d人物控制

u3d人物控制

dir 碰撞 sys pos com scree mouse arp erl

//https://blog.csdn.net/Htlas/article/details/79188008
//人物移動 http://gad.qq.com/article/detail/289212
//mesh  山丘地形 http://gad.qq.com/article/detail/289108

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Cube : MonoBehaviour {
    public EasyTouchMove touch;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        //獲取horizontal 和 vertical 的值,其值位遙感的localPosition
        float hor = touch.Horizontal;
        float ver = touch.Vertical;
 
        Vector3 direction = new Vector3(hor, 0, ver);
 
        if(direction!= Vector3.zero) {
            //控制轉向
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(direction),Time.deltaTime*10);
            //向前移動
            transform.Translate(Vector3.forward * Time.deltaTime * 5);
        }
	}
}

//2D碰撞檢測
// Collider2D[] col = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));
 
// if(col.Length > 0)
// {
//     foreach(Collider2D c in col)
//     {
//          //do what you want
//     }
// }

  

u3d人物控制