问题
I am using unityscript and I have no idea why but the OnCollisionEnter Function never calls, even when logging it in unity3d. Is there an alternative or a reason why this is happening?
By the way I am trying to use this collision detection function to find out if the Main Camera is touching a wall or anything.done
This is exactly what I have done:
- I created a unityscript file.
I replaced all the contents with just:
function OnCollisionEnter(theCollision : Collision) { Debug.Log("Hit"); }
Now I drag that file, having been saved, to Main Camera.
- In the game I move the main camera to a wall or cube object, but it does not Log "Hit".
Thanks
回答1:
- First Check If the script is attached to the GameObject.
- Then check if there is RigidBody Component attached to a GameObject(on which you are attaching the script with OnCollisionEnter)
Post the code so we can get better idea
来源:https://stackoverflow.com/questions/12884352/function-oncollisionenter-not-working-unity