How can I delete the object in front of the camera?
var Voorwerp : GameObject;
var positieVoor : Vector3;
if (Input.GetMouseButtonDown(1)){
Destroy(Voorwerp,positieVoor,Quaternion());
How can I delete the object in front of the camera?
var Voorwerp : GameObject;
var positieVoor : Vector3;
if (Input.GetMouseButtonDown(1)){
Destroy(Voorwerp,positieVoor,Quaternion());
Use Physics.Raycast.
This example script is meant to be placed on the camera. You might want to see the ref link about how to use layermasks to prevent destroying self.
function Update () {
if (Input.GetMouseButtonDown(1)) {
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit)) {
Destroy(hit.transform.gameObject);
}
}
}