C# programming term needed

I just need a term so I can look up examples. I’m looking at manipulating variables stored in another script. Here’s a basic example of what I’m trying to accomplish.

store.cs
using UnityEngine;
using System.Collections;

public class store : MonoBehaviour {
	
	
	//Variables
	
	private int num1;
	
	
	
	//Variables - END
	
	
	
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

updater.cs
using UnityEngine;
using System.Collections;

using store;


public class Updater : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
		
		if (Input.GetKey("up"))
		{
			
			store.num1 = store.num1 + 1;
				Debug.Log("Num1 = " + store.num1);
			
		}
		
		
		if (Input.GetKey("down"))
		{
			store.num1 = store.num1 - 1;
				Debug.Log("Num1 = " + store.num1);
			
		}
		
	}
}

So if a player hits the up key, num1 adds + 1 to itself, and the down key will subtract one from itself. Again, if anyone knows the tem for this, I’ll be happy to look it up myself. Thank you kindly!

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

It looks like you want to use static variables (and also make them public). However, keep in mind that a static variable is the same for all instances of the class, so if you had 2 GameObjects with the “store” component, they’d both reference the same variable. The code would look like this:

public static int num1;

If you have more than 1 “store” GameObject, you could create a property to manipulate the values. If you do that, you’ll need to get a reference to your GameObject in your updater.cs script. You could do this by adding the following code at the top:

public store myStore;

Then, set the value of myStore in your unity scene. Then, later in the script use the myStore variable to change the values.

This is actually pretty simple. You just need to make sure the scripts are actually attached to objects in the current scene, then you can reference then. I created a sample scene for you… Create a new Test Project in Unity and open the scene.

Clicking Arrow up in the “player object” and you will see the “Score” variable going up in the ScoreManager object.
In your scripts make sure the variables you are trying to expose are public. I can see in your example above, your “num1” variable in the “store” script is private, that would not work even if you referenced correctly… make your variables public when needed.

Download test Scene here