What are Private and Public voids and their differences?
In Unity, you’ll often come across a situation where you’re forced to choose between using a Private and a Public void, and, being as important as they are, you are required to choose the correct one. So, what is the difference between the two? A Private void is a void (A system where nothing is given in return unless it’s within its own system) where nothing outside of its category can influence or change its status, while the Public void is able to be modified by anything, be it ourside or inside its own category.
private void OnMouseDown(){
mouseUnpressed = false;
offsetX = Camera.main.ScreenToWorldPoint(Input.mousePosition).x - transform.position.x;
offsetY = Camera.main.ScreenToWorldPoint(Input.mousePosition).y - transform.position.y;
}
In the code above, you can see an example of a private void being used. The code’s function is to move an object while the mouse is down, hence why it is important that nothing out of that category is able to modify it.
EduardoL
0