using UnityEngine;
using System.Collections;
/*
*物体移动到鼠标左键点击处
*/
public class PlayerMovePos : MonoBehaviour {
private bool finish = true;
private Vector3 pos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//物体每次移动一定距离到鼠标点击处
//if (Input.GetMouseButtonDown(0))
//{
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit hit = new RaycastHit();
// if (Physics.Raycast(ray, out hit))
// {
// pos = hit.point;
// pos.y = 20f;
// finish = false;
// }
//}
//if (Input.GetMouseButtonUp(0))
//{
// finish = true;
//}
//if (!finish)
//{
// Vector3 offset = pos - transform.position;
// transform.position += offset.normalized * 100 * Time.deltaTime;
// if (Vector3.Distance(pos, transform.position) < 1f)
// {
// transform.position = pos;
// finish = true;
// }
//}
//物体直接出现在鼠标左键点击的位置
//if (Input.GetMouseButtonDown(0))
//{
// Vector3 screenpos = Input.mousePosition;
// Ray ray = Camera.main.ScreenPointToRay(screenpos);
// RaycastHit hitinfo = new RaycastHit();
// if (Physics.Raycast(ray, out hitinfo))
// {
// pos = hitinfo.point;
// transform.position = new Vector3(pos.x,transform.position.y, pos.z);
// }
//}
}
}
使用请去掉注释!!!