I want to make a script where when you look at a cube, you can press the left click button, that i named "Break"
function Update () {
if(GetAxis("Mouse Y")) {
GetAxis("Mouse X");
Input.GetButton("Break");
Destroy (gameObject);
}
}
Since i'm new to Unity, can someone tell me, how
if axis Mouse Y and Mouse X are on gameobject, it needs the break button to destroy the game object? I'm sorry if my codings REALLY different from what its suppose to be.
There are a couple ways you can approach this. The easy way would be to:
//This goes on your cube.
function OnMouseDown () {
Destroy(gameObject);
}
This will work as long as you have a collider on your cube. This function is called when the user clicks on your Collider.
You could also raycast from the camera and detroy the object that you hit:
//This goes on anything you want really. Logic would say it goes on the camera though.
function Update () {
if (Input.GetButton("Break")) {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
Destroy(hit.collider.gameObject);
}
}
}