unity onclick object 1

unity onclick object

 void Update () {
     
 }
  void OnMouseDown(){
         // this object was clicked - do something
     Destroy (this.gameObject);
  }   

Here is what the above code is Doing:
1. The first line of code is a comment. Comments are ignored by the computer. They are used to explain what the code is doing.
2. The next line of code is a function. Functions are a way to group code together. This function is called Update. It is a special function that is called every frame.
3. The next line of code is a comment.
4. The next line of code is a function. This function is called OnMouseDown. It is a special function that is called when the mouse is clicked on this object.
5. The next line of code is a comment.
6. The next line of code is a function. This function is called Destroy. It is a special function that destroys the object that it is called on.
7. The next line of code is a comment.

Similar Posts