I'm working on a point and click system in Unity and I have a contextual menu that appears when you right click on an object. In this menu, there's a button called "search" that moves the player to the object and opens a menu representing that object's contents. The Search Button calls a method that takes a gameobject as a parameter; in other words, the object that the player treats as the target to which it moves and then searches.
All of this is working just fine, but there's one problem: Currently I have two test containers, a crate and a barrel. The crate is the object that the button is taking as a parameter, so if I right click the barrel and select "search", the player will go to search the crate.
How do I dynamically change the gameobject target of the button so that the search button will know the correct object it should be targetting, I.E. whichever object the player right clicked?