Hello all!
I’ve been trying to instantiate a gameobject at the mouse position. I know to do this I need to use RaycastHit, but when I try to instantiate with Instantiate(waypoint, hit.point, Quaternion.identity);
, it doesn’t work. The console doen’t say that there are any errors, but when I try to use the script, nothing happens. Any ideas?
Full script:
#pragma strict
var waypoint: GameObject;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
if (hit.rigidbody != null)
Instantiate(waypoint, hit.point, Quaternion.identity);
}
}
}