Hello, I am a new-comer to Unity and am currently working on a learning project. However scripting is something that I have trouble with. Currently I am trying to make a script to detect when two objects collide and remove both. However I can't get it to work? Help would be much appreciated.
asked May 12 '10 at 11:03 PM
One issue that can be solve right away, is that you don't need to nest the OnTriggerEnter inside of the Update. So you can remove the Update right away. This and the next issue are the only things that make your code not work.
Another thing, You need to declare a variable wall. That way Unity knows what to destroy. That is probably what was keeping your script from compiling.
If you want some other advice for generally improving your code you can continue, otherwise, that is the answer to your problem.
Next, Your OnTriggerEnter, is combining 2 methods together. It should actually still work, but you see, OnTriggerEnter(col : Collider) requests the collider that entered the trigger (or the trigger depending on what gameobject has this script attached. Remember it returns the other of the two possibilities.) And, you have provided the Collision information which is used in OnCollisionEnter(). So your script could either read.
or, since you are not using actually using any of that information, you can just take it out also. Which will save you memory if you are running low.
answered May 12 '10 at 11:20 PM
Your problem is in the
That should do the trick!
answered May 12 '10 at 11:13 PM