void Update()
{
//鼠标点击地面,点击地方实例化一个小球,1秒后销毁
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isco = Physics.Raycast(ray, out hit);
{
//鼠标点击地面,点击地方实例化一个小球,1秒后销毁
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isco = Physics.Raycast(ray, out hit);
//点击的物体设个(Player)标签
if (isco && hit.collider.tag == "Player")
{
if (isco && hit.collider.tag == "Player")
{
//加载物体
GameObject go = Instantiate(Resources.Load("sphere") as GameObject, hit.point, Quaternion.identity);
GameObject go = Instantiate(Resources.Load("sphere") as GameObject, hit.point, Quaternion.identity);
//1秒后销毁
Destroy(go, 1f);
}
Destroy(go, 1f);
}
}