Okay, I understood the first part, but the second part of your question was difficult to understand.
Here is one way:
–Make sure both scripts are on gameObjects
And then simply:
–find that gameobject
–then access the script (as a component) of that gameObject. All those things you add into the editor window over there on the right hand panel. The transform, the collider, the mesh… all those things are components, just FYI
So if have a gameObject with all of the inventory related data. Let’s just call it InventoryData for ease sake. It has this script on it called Inventory.cs. You also have to change the tag on this game object to InventoryData so that we can find it and access it quickly.
float myGunDelay;
myGunDelay = GameObject.FindGameObjectWithTag ("InventoryData").GetComponent <Inventory> ().gunDelay;
we are saying that MY gunDelay ← I say MY because it is the gunDelay for this script, the player = Find the object we already tagged and grab it’s component , that script we called Inventory… and the we retrieve the variable inside of it called gunDelay.
How you are operating your inventory is completely unknown. You should probably look into “creating structures in c#”. An easy way as I am a beginner also is to do something like this inside your inventory:
public float gunDelay;
public string gunDescription;
public int gunDamage;
void update ()
{
}
public void UpdateTheData (int gunTypePassThrough)
{
//if the gun type is 1
if (gunTypePassThrough == 1)
{
gunDelay = 2.3f;
gunDescription = "pistol";
gunDamage = 20;
}
}
And then to use it; You just simply say Okay… I am going to make my #1 a pistol, and 2 will be a shotgun and 3 will be a laser. Or whatever… And then you just call it from within the script by typing:
UpdateTheData (1);
Or call it from outside of the script…
// if you wanted to tell the inventory script that now you have the shotgun (#2).....
GameObject.FindGameObjectWithTag ("InventoryData").GetComponent <inventory>().UpdateTheData (2);
//You could also find out what the players current gun is the same way...
myGunDelay = GameObject.FindGameObjectWithTag ("InventoryData").GetComponent <inventory>().gunDelay;
myGunDescription = GameObject.FindGameObjectWithTag ("InventoryData").GetComponent <inventory>().gunDescription;
myGunDamage = GameObject.FindGameObjectWithTag ("InventoryData").GetComponent <inventory>().gunDamage;