public class born : MonoBehaviour
{
//鼠标点击克隆物体
GameObject CloneMuban;
void Start()
{
CloneMuban = GameObject.Find("Cube (2)");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Ray OneRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit OneObj;
if (Physics.Raycast(OneRay, out OneObj))
{
Debug.Log("用户按下了鼠标左键");
if (OneObj.transform.gameObject.name == "r")
{
GameObject.Instantiate(CloneMuban, OneObj.point, Quaternion.identity);
}
}
}
}
}
示意图: