I Have this “store script” so when the player press “b” a market menu is showing and the player can buy items.
Im trying to make it so that the market only can be opened in 1 special building at the moment players can open it everywhere.
You will want to add a trigger. Create a trigger the size of the area you want the player to be able to open the store.
Use the OnTriggerEnter and OnTriggerExit to set a variable in your player object (“bool isInStore”) to either true or false depending on whether the player is inside that area. You will need to check the tag of the object entering the trigger (“Player” or whatever you are using for your player), and you will have to make sure your player object has a rigidbody attached (if it doesn’t already).
Then when they press “b” you check " if (player.isInStore)" and only open if that conditional succeeds.
I Got this Store script attatch too a empty gameobject, With a Box collider marked as trigger inside the storebuilding. Do i need to put the ontriggerenter and exit script on the player? or the store Object? thx for Your fast reply
add the following to your current script in the appropriate places
var targetObj: Transform; //Use the inspector to drag and drop your shop into here from the hierachy
function Update () {
//Assuming your shop script is called shop script this will work
//otherwise no worries just change them both to whatever your script is called!
var otherScript: ShopScript = targetObj.GetComponent(ShopScript);
otherScript.OpenMenu();
}
in your shop object make a function called “OpenMenu” and your collision script will trigger the function in your shop script.
EXAMPLE:
function OpenMenu () {
//and put your shop menu script in here!
}