I want to use this int in the two scripts: public int wood;
I want the value of the int to be the same in both scripts.
This is my first script:
public class Tree :
MonoBehaviour { public int wood;
private void OnTriggerEnter2D(Collider2D collision)
{
wood += 1;
}
}
This is my second script which I want the wood to use in it:
public class Base : MonoBehaviour {
private void OnTriggerEnter2D(Collider2D collision)
{
}
}
I want to decrease the wood value in OnTriggerEnter2D. How do I do that?
You can add the button component to your gameobject.(To get this component in code use
Button btn = Gameobject.GetComponent<Button>();. To detect a click on the button you can use theonclickevent the button has.You can also add the
OnMouseDownandOnMouseUpfunctions to create a button(this would only require the collider component, and not the button component.