function OnCollisionEnter() not working unity

折月煮酒 提交于 2019-12-25 03:01:05

问题


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:

  1. I created a unityscript file.
  2. I replaced all the contents with just:

    function OnCollisionEnter(theCollision : Collision) {
         Debug.Log("Hit");
    }
    
  3. Now I drag that file, having been saved, to Main Camera.

  4. In the game I move the main camera to a wall or cube object, but it does not Log "Hit".

Thanks


回答1:


  1. First Check If the script is attached to the GameObject.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!