0
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.