I'm a complete beginner in Unity 3D, and I'm following a video training. In the video the instructor uses the following code to open a door using raycast:

using UnityEngine;
using System.Collections;

public class HelloRaycasting : MonoBehaviour {

    bool doorClosed = true;

    // Use this for initialization
    void Start () {


    // Update is called once per frame
    void Update () {

        Vector3 backward = new Vector3 ( 0, 0, -1);
        Vector3 origin = this.gameObject.transform.position;

        if (Physics.Raycast( origin, backward, 1f) && doorClosed) {
            doorClosed = false;
            GameObject.Find ("Left_Quad").transform.Translate ( new Vector3(-.8f, 0, 0));
            GameObject.Find ("Right_Quad").transform.Translate ( new Vector3(.8f, 0, 0));

It works just fine for him. But when I try to run this on my computer I get this error:

Assets/HelloRaycasting.cs(20,29): error CS0117: 'Physics' does not contain a definition for 'Raycast'

In the end I'm not able to access none of the properties and methods of the Physics class.

I'm using Unity 5.3.2f1 (64-bit). What am I doing wrong?


I'd guess you made your own class or imported some other class named Physics. Try fully qualifying it UnityEngine.Physics.Raycast.

Alternatively, you can make sure you make a clean build to ensure there's nothing left over that's messing up your build.

  • 1
    \$\begingroup\$ You're correct. I had some draft script named as Physics, just deleted it and problem solved. Thank you. \$\endgroup\$
    – adamasan
    Feb 26 '16 at 19:42

In addition to what Byte56 has said, apply


where you are using the Physics.Raycast method.

  • 2
    \$\begingroup\$ This doesn't appear to add any information not already present in the accepted & upvoted answer from last year. \$\endgroup\$
    – DMGregory
    May 2 '17 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .