赞
踩
脚本挂在移动物体上,判断射线点击层设置标签为Plane
public class Playmove : MonoBehaviour {
Ray ray;
RaycastHit hit;
bool state = false;
public float moveSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,out hit))
{
if (hit.collider.tag == "Plane")
{
state = true;
}
}
}
if (state)
{
transform.forward = Vector3.Lerp(transform.forward, hit.point - transform.forward, Time.deltaTime);
transform.position = Vector3.MoveTowards(transform.position, hit.point, Time.deltaTime*moveSpeed);
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。