My question is this: say i had a variable called BlueAmmo, and it was equal to 0, in one script. In another script i want to say when i shoot a blue bullet it depletes the BlueAmmo count by one. In addition, in another script, when i pick up an ammo pack, BlueAmmo is increased by 10. I know how to do the, when shot decrease BlueAmmo by 1 in the same script as the variable. My objective is to do this in 2 diffrent scripts, with one variable.
P.s. I know it should by a float not a variable.
Thanks for what ever help you can give 
Whole situation:
I am creating a game that there are four different types of bullets: blue, red, yellow, and purple. Blue is freeze, red is fire, yellow is paralysis, and purple is poison. I need the ammo for each of these colors, and the shooting portion of the ammo, to be in separate scripts for organization. In addition to this, I have to have ammo packs for each of these colors. Not to mention triggers for colliders, And terrain. As you can see, it would be very hectic if for each color it had all the mesh and shoot scripts in one.
So what you are looking for is GetComponant
This unity tutorial dose an excellent job of explaining what you need to do.
Hope it helps you @austinlayne7
Have BlueAmmo as a public variable (or make a public get method if private), and just get the Component on the game object to get BlueAmmo from other scripts attached to the game object. Something like below:
Gun:
public int BlueAmmo = 0;
Shoot Gun:
Gun gun;
void Awake(){
gun = GetComponent<Gun>();
}
void Update(){
ShootGun();
}
void ShootGun(){
if(player press the shoot button)
scriptA.BlueAmmo--;
}
You’ll have to do additional logic for picking up ammo such as using colliders if that’s your route but it would work similarly to how this works. Make sure the scripts are on the same game object. I hope this helps.
If you only need one instance, you can use a static property, in a static class even, unless you need MonoBehaviour features.
static public class Supplies
{
static public float blueAmmo;
}
Then from any script, you can simply call :
Supplies.blueAmmo ++;
Supplies.blueAmmo --;
Hello @austinlayne7 Well. The ways to access vars that I know
-
make your variable as public then in your second script use GetComponent<FirstScript>().blueAmmo
-
If your variable is private and you want to keep it private in the future you can try using getters and setters. Somthing like this:
//FIRSTSCRIPT
private int blueAmmo;
public int BlueAmmo
{
set { blueAmmo= value; }
get { return this.blueAmmo; }
}
and in your second script
//SECONDSCRIPT
public FIRSTSCRIPT firstScript;
public int supplies;
void Start(){
firstScript.BlueAmmo = supplies;
}
I’am not pretty shure about getters/setters if it’s correct but you can try play around and check.
-
Also you can try singleton http://wiki.unity3d.com/index.php/Singleton
For example:
public class FirstScript: MonoBehaviour {
public int blueAmmo;
private static FirstScript instance;
public static FirstScript Instance
{
get
{
return instance;
}
}
void Awake()
{
CreateInstance();
}
void CreateInstance()
{
if (instance == null)
{
instance = this;
}
}
and then:
public class SecondScript: MonoBehaviour {
public int supplies;
void Start(){
FirstScript.Instance.blueAmmo = supplies;
}
Hope this helps. Good luck