Currently I’m in a bit of a pickle. I’m trying to accomplish something which for some reason just won’t work.
Basically, what I’m trying to achieve is be able to swap what gameobject is assigned to a variable during runtime.
For example:
Game starts, character is holding object which is assigned to the variable objectHeld. When the character walks over another object on the floor and it’s in the character’s trigger, I press a key which then should swap what the character is holding with the object on the floor. However, it seems Unity doesn’t like having the inspector change during runtime. I have even tried making the character drop the held object and made the variable be null but that doesn’t work either.
Does anyone have any ideas or solutions to this problem? I seem to be stumped.
The variable in the inspector stays to the original object, it won’t swap to anything else. So you could please point out what I’m doing wrong and point me on the right path?
I have no idea why I was using OnTriggerEnter. Such a simple mistake. Another mistake I figured out is that I should have just used GetKey instead of GetKeyDown.