I'm having some trouble with my script. I'm getting an error.
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
I'm using referenceScript to pull information from Inventory.
public class referenceAnotherScript : MonoBehaviour {
void Start(){
myinventory = gameObject.GetComponent();
weaponsclass = gameObject.GetComponent();
}
public GameObject mySphereObject;
private Inventory myinventory;
private weaponsClass weaponsclass;
private float windowX = 20.0f;
private float windowY = 50.0f;
void OnGUI() {
GUI.Label (new Rect (windowX, windowY, 500, 20), weaponsclass.weaponName.ToString());
windowY = 20f;
for (int j = 0; j < myinventory.myWeaponArrayList.Count; j++) {
GUI.Label (new Rect (windowX, windowY, 100, 20), myinventory.myWeaponArrayList[j].ToString());
windowY += 20f;
}
}
void OnTriggerEnter(Collider collider){
if (collider.name == "mySphere") {
weaponsClass newWeapon = new weaponsClass("Ice","Sword", 0, 5);
}
}
}
Inventory
public class Inventory : MonoBehaviour {
public ArrayList myWeaponArrayList = new ArrayList(){"Weapons:"};
public class myInventory
{
public string itemName;
public string itemType;
public myInventory(string Name, string type){
itemName = Name;
itemType = type;
}
}
}
Ideally I want to be able to store my 'weapons' information in like, an array. But i'm not too sure how to do it, if anyone can link me to a weapons class tutorial or something that'd be great.
↧