Hello, I am creating an object class for a weapon system at runtime and I want to be able to call a method like “Shoot” from outside on a player class. How could I call ShootObject without adding it as a component?
Would I have to attach the Object manager to it’s created object in order to call ‘ShootObject()’ method? Is this the best way to do this? I was under the assumption when you created an object it came with all it’s methods and properties:
>ObjectManager.cs
public void CreateNewObject()
{
ObjectClass newObject = new ObjectClass();
}
>Objectclass.cs
public ObjectClass()
{
GameObject newGameObject = new GameObject();
newGameObject.AddComponent <ObjectClass>();
//DO I DO THIS? ^
}
public void ShootObject()
{
//blah
}
>PlayerClass.cs
void UseObject()
{
ObjectClass oc = currentHoldingGameObject.GetComponent<ObjectClass>();
oc.ShootObject(); //Null refrence
}
thanks,