Click here to Skip to main content
15,745,620 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've built a vehicle shop in the game
this code not working for me and not be destroy object

What I have tried:

public GameObject trigger;
	public GameObject PressEpanel; 

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	public void OnTriggerEnter(Collider col)

		if (col.gameObject.tag == "Player") {

			PressEpanel.SetActive (true);

	public void OnTriggerExit(Collider col)
		if (col.gameObject.tag == "Player") {

			PressEpanel.SetActive (false);


	public void OnTriggerStay (Collider col)
		if (Input.GetKeyDown (KeyCode.E)) {

			if (col.gameObject.tag == ("Car")) {

				Destroy (col.gameObject);

Updated 9-Aug-19 15:02pm
ZurdoDev 9-Aug-19 11:57am    
You'll need to debug your code.

We can't help you with that, without the whole system that code is running as part of - and we don't have that, and don;t want it - we'd have to learn your whole game and it's ode in order to test it!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
Share this answer
this code not working for me

There nothing we can do with this code, I fear you will have to learn how to debug your code. Fortunately, the debugger is an incredible learning tool.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging C# Code in Visual Studio - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900