Hello! I am trying to create a shop with a UI interface. My problem is when the player enter in the collider of the object (Kiosk) the UI will not pop out. I tried everything I know.
Can you write the correct script for this application or can you tell me what I need to do so the application works?
This is what I am trying to do:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenShop : MonoBehaviour
{
private GameObject shop;
private void Start()
{
shop = GameObject.Find("Background");
shop.SetActive(false);
}
private void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
shop.SetActive(true);
}
}
private void OnTriggerExit(Collider col)
{
if(col.gameObject.tag=="Player")
{
shop.SetActive(false);
}
}
}
Hello @Tud123,
So you will make a new post everytime you have an answer instead of testing it and answering ?
You made 4 times the same post already…
We have no idea what you are stuck on, you didn’t answer the previous posts, but let me give you some tips and a resume of what other people said in your previous posts:
-
You need a player with a rigidbody attached to it and not kinematic if you want an interaction with your shop, it means the player needs to move with physics
-
You need your player to have the tag “Player” selected
-
Your shop needs to have a BoxCollider set isTrigger
-
In the OnTriggerEnter function you can add a Debug to display a message and check the console to see if it works, it would be the first step to know if there is an interaction:
Debug.Log("collision triggered with: " + col.gameObject.name);
-
If you have a message in the console when you collide with the shop it means the trigger works and the problem lies somewhere else
-
Your shop UI need to be setup correctly to be displayed on screen so you need to check before launching the play mode
-
Your private GameObject shop needs to be either public or [SerializeField] in order for you to set it in the inspector
-
You need to check the console for errors to figure out what’s going bad and share it with us
Okay so the problem was that the player had the Rigidbody but the Capsule Collider was on it’s child so the “Player” tag needed to be set on the child and not on the player itself because when the collision/trigger occurs the Collider is used as a reference in the variable Collider