Can't use code from another class, even though it's public and in the same namespace.

I have a gameobject called “Paddle”, this gameobject has the script PaddleScript attached to it.
I have another gameobject called “Brick”, this gameobject has the script BrickScript attached to it.

Both scripts reside in the MyGame namespace and are public classes.

Now PaddleScript has the following code:

namespace MyGame
{
	public class PaddleScript : MonoBehaviour 
	{
		int intScore = 0;

		public void AddPoint(int scoreInput)
		{
			intScore = intScore + scoreInput;
		}
	{
{

This code works fine. (But I’m not sure if AddPoint is a method or a constructor.)

I want to access AddPoint from the script BrickScript.
Here are the two things I did, one works and the other one doesn’t work.

namespace MyGame
{
	public class BrickScript : MonoBehaviour 
	{
		int pointValue = 1;
				
		void OnCollisionEnter( Collision col)
		{
			Destroy ( gameObject );

			// Code that works.
			GameObject.Find ("Paddle").GetComponent<PaddleScript>().AddPoint(pointValue);

			// Code that doesn't work.
			PaddleScript.AddPoint(pointValue);
		}
	}
}

My question is, why does the latter not work? Both classes are public and reside in the same namespace.

The comments only half answer the question.

GameObject.Find ("Paddle").GetComponent() returns a specific instance of the PaddleScript class

conversely

PaddleScript.AddPoint() actually calls the method on the class.

Making the method/variables static means that there is only one “paddlescript” in existence, and any instances of it all have the same values.

Most of the time, making things static like that is kind of a hack-y way to get it to work, because conceptually you’re trying to use one instance, but that’s not exactly what static means.

Referencing a GameObject with a PaddleScript component is more correct because that is one specific PaddleScript object.

If you use static functions/variables and ever create another PaddleScript object you’ll run into a lot of issues.

For example. If you keep your script as is, and create two GameObjects with PaddleScripts, each paddle would have it’s own score. If this was a two player game, that’s probably what you want.

On the other hand, if you changed it to be a static variable, whenever you call AddPoint() ALL paddles in the scene would get points added, which is usually not the desired behavior.