Collecting bullet and update Custom UI bullet count
Hi creators,
I'm using the Chop n Pop as reference. My goal is to collide with the trigger (treating it as a bullet collectable). When triggered, increase the count on the UI. However, the UI count is not being updated.
Here is what I have done:
I have a CustomUITrigger.ts attached to a Trigger and a HeadsUpDisplay.ts attached to a CustomUI
In play mode, I have Custom UI display an image and count of "0"
Here is my CustomUITrigger.ts. OnPlayerEnterTrigger is being called because I have a console.log thats gets printed everytime I collide with the trigger. However, this.ammoUi?.updateCount(this.ammoCollected++); this not appear to do anything. I know it is because ammoUi is null, but I don't get why it is null.
Here is my HeadsUpDisplay.ts (split into two images). I'll be honest, the UiComponentsRegistry was copied straight from Chop n Pop. I have no clue what it is doing which may be why ammoUi is null....although when I added a console log to see if entity id had a value, it did print, it wasn't entering the if statement where it checks if entity was null.
and here updateCount isn't getting called because of null mentioned earlier.
One thing to note. In CustomUITrigger.ts , preStart() where I call this.ammoUi = UiComponentsRegistry.GetComponent<HeadsUpDisplay>(this.props.ammoUIDisplay);
In Chop n Pop it is being called in onAllocate,but I'm not sure what that's doing either. Since it is just getting a component, I thought adding this in preStart would work. Maybe that's also another reason why it's not working.
Thanks to the tutorial from here, I learned how to display custom UI based on triggers: Mobile Worlds Crash Course with Laex05: https://communityforums.atmeta.com/t5/Community-Resources/Mobile-Worlds-Crash-Course-with-Laex05-Now-Available/td-p/1303353