I am having an issue trying to access another script’s variables from another script. Both of these scripts I am referencing to are on separate gameobjects. Script I am trying to access is named “InventoryS2” and the gameobject is named “ThePlayer”. The second script is called “MobT” and the gameobject it is on is called “Cube”.
InventoryS2(Only Showed the relevent code, rest is GUI related things.)
using UnityEngine;
using System.Collections;
public class InventoryS2 : MonoBehaviour
{
private int Menu,Options,Inventory,Map,Skills,Stats = 0;
public Vector2 scrollPosition = Vector2.zero;
public float GoldCount = 0;
MobT
using UnityEngine;
using System.Collections;
public class MobT : MonoBehaviour
{
public float GoldDrop;
public InventoryS2 Inventory;
void Awake()
{
Inventory = GameObject.Find("ThePlayer").GetComponent ("InventoryS2");
}
void OnMouseDown()
{
GoldDrop = Random.Range (0,10);
Inventory.GoldCount = Inventory.GoldCount + GoldDrop;
Destroy (gameObject);
Debug.Log (GoldDrop);
}
}
MobT is designed as a purpose of testing for when I click on the gameobject it will be destroyed and the GoldCount of the InventoryS2 script will increase at random between 1 and ten.
I would like responses that don’t tell me to use static variables.