Count Value of Object in triggerzone,Checking value of Item ontrigger

Hi Guys !
I’m new and need some help.
I made a Store and want to count/read out a value of different items (for example banana: 5$, TV 500$) when they are thrown into a trigger zone (Box Collider trigger).
Can someone help me out ?,Hi guys.
I’m new here and got a problem.
I want to give different items (gameobjects), different values (for example a banana 5$ and a TV 500$) and read out/count this values, if the item is thrown into a trigger zone.
I don’t know how to do it, can someone help me out ?

Do you have a script assigned to the objects containing their price? If not, you should create a script that looks like this at least:

public class Value : MonoBehaviour
{
     public float price;
}

Then, in the inspector, if you assign the script to a TV, you can set the price property to 500. Same for a banana as well.


Finally, you’ll need a script on the trigger collider that gets the object that collided with it. For example:

public class ObjectTrigger : MonoBehaviour
{
     void OnTriggerEnter(Collider other)
     {
          Value valueScript = other.gameObject.GetComponent<Value>();

           // Gets the price of the object that entered the trigger zone
          Debug.Log(valueScript.price);
     }
}

@timbonn

Thank you !
That looks so much simpler than anything that I tried.

Have to code more by myself to learn it.