Script's function not firing

I have these two scripts and the result isnt occurring… Its not calling the ‘doAction’ function in this script for some reason

 private InfoBox _playerActionsDesc;
 
     void Start() {
        _playerActionsDesc = new InfoBox();
		doAction ();
    }
 
     void doAction() {
        if(Input.GetKey(KeyCode.Q)) {
			Debug.Log("here1");
            _playerActionsDesc.choppingWood();
			//actions
		}
	}

the scripts are on the same objects…

Not sure what you’re trying to do but unless you’re holding Q when the game starts you won’t see any changes

Are you sure you don’t want to have something like:

private InfoBox __playerActionsDesc;

void Start(){
  _playerActionsDesc = new InfoBox();
}

void Update(){
  if(Input.GetKey(KeyCode.Q)){
    DoAction();
  }
}

void DoAction(){
  Debug.Log("Here");
  _playerActionsDesc.choppingWood();
}

}

InfoBox is a MonoBehaviour, and you can’t instantiate MonoBehaviours. So, line 4 of you original code:

_playerActionsDesc = new InfoBox();

should give a warning in the log. If you google “unity3d instantiate monobehaviour”, you’ll find many links on the subject.

So, if you MUST instantiate InfoBox, make it inherit from “ScriptableObject” instead of MonoBehaviour, but methods like Start and Update won’t be available. Alternatively, attach an InfoBox script on an empty GameObject in the hierarchy. Then get a reference to that InfoBox component (several ways to do that), and remove the instantiation on line 4.

This should generally do the trick.