I want to run a function from another script. the scripts are on separate objects dunno if that matters
`public class Chop_wood : MonoBehaviour {
public int inventory = 0;
void OnTriggerEnter (Collider col)
{
Debug.Log ("at the tree");
//Chop ();
}
public void Chop()
{
inventory++;
Debug.Log ("i am chopping the wood");
}
void Update ()
{
}
}
`
And here is the other script, im trying to run the Chop() function but it tells me
Object reference not set to an instance of an object
chopped.OnTriggerEnter (UnityEngine.Collider col) (at Assets/chopped.cs:20)
public class chopped : MonoBehaviour {
public Chop_wood chopWood;
void Start()
{
chopWood = GetComponent<Chop_wood> ();
}
void OnTriggerEnter (Collider col)
{
if (col.collider.name == "Pirate_Chopper")
{
Debug.Log ("in the trigger");
chopWood.Chop();
}
}
void OnTriggerStay (Collider other)
{
}
}
the funny thing is it worked once and that time it still gave me the error, whats wrong?