# Raycast problem!

**URL:** https://discussions.unity.com/t/raycast-problem/600589
**Category:** Physics
**Tags:** Scripting
**Created:** [October 7, 2015, 6:35pm UTC](https://discussions.unity.com/t/raycast-problem/600589 "2015-10-07T18:35:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![DrunkProgrammer](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DrunkProgrammer](https://discussions.unity.com/u/DrunkProgrammer)
#### Post date: [October 7, 2015, 6:35pm UTC](https://discussions.unity.com/t/raycast-problem/600589/1 "2015-10-07T18:35:45Z")

</div>

```csharp
using UnityEngine;
using System.Collections;

public class RayCastScript : MonoBehaviour {

    static float distance1 =5;

    void Update() {
        RaycastHit hit;
        Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit);
        distance1 = hit.distance;
    }
}

```

Assets/Scripts/RayCastScript.cs(10,50): error CS1525: Unexpected symbol `’

Does anyone knows what is wrong with the above code?

---

<div class="post-metadata">

### Author: ![Thomas-Mountainborn](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@Thomas-Mountainborn](https://discussions.unity.com/u/Thomas-Mountainborn)
#### Post date: [October 7, 2015, 6:39pm UTC](https://discussions.unity.com/t/raycast-problem/600589/2 "2015-10-07T18:39:59Z")

</div>

The hit variable needs to be passed as “out”:

```auto
Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit);

```

Also, as a side note, you could use “transform.forward” directly, instead of transform.TransformDirection(Vector3.forward).

---

<div class="post-metadata">

### Author: ![StarManta](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/starmanta/32/280327_2.png) [@StarManta](https://discussions.unity.com/u/StarManta)
#### Post date: [October 7, 2015, 6:40pm UTC](https://discussions.unity.com/t/raycast-problem/600589/3 "2015-10-07T18:40:52Z")

</div>

Well, that is an unusually unhelpful error message. But most likely, the issue is that ‘hit’ should be ‘out hit’, as it’s an output parameter.

---

<div class="post-metadata">

### Author: ![DrunkProgrammer](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DrunkProgrammer](https://discussions.unity.com/u/DrunkProgrammer)
#### Post date: [October 7, 2015, 6:49pm UTC](https://discussions.unity.com/t/raycast-problem/600589/4 "2015-10-07T18:49:02Z")

</div>

```csharp
using UnityEngine;
using System.Collections;

public class RayCastScript : MonoBehaviour {

    static float distance1 = 5;

    void Update() {
        RaycastHit hit;
        Physics.Raycast(transform.position, transform.forward, out hit);
        distance1 = hit.distance;
    }
}

```

I changed the code to that but the problem consists!

---

<div class="post-metadata">

### Author: ![Thomas-Mountainborn](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@Thomas-Mountainborn](https://discussions.unity.com/u/Thomas-Mountainborn)
#### Post date: [October 7, 2015, 6:55pm UTC](https://discussions.unity.com/t/raycast-problem/600589/5 "2015-10-07T18:55:26Z")

</div>

Hmm, there’s something strange going on in that file then. Try making a new script and pasting those statements in there, see if the problem persists.

---

<div class="post-metadata">

### Author: ![StarManta](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/starmanta/32/280327_2.png) [@StarManta](https://discussions.unity.com/u/StarManta)
#### Post date: [October 7, 2015, 6:56pm UTC](https://discussions.unity.com/t/raycast-problem/600589/6 "2015-10-07T18:56:37Z")

</div>

Something strange is going on. Since I’ve never seen that error before, I copied and pasted your code into a CS file, and it compiled without a problem. This suggests to me that something weird is going on with either the file or the project. Can you describe anything out of the ordinary you might have in your project? Any packages or plugins, have you played with the player settings, etc, etc? Oh, and does your script have the correct extension (cs)?

---

<div class="post-metadata">

### Author: ![DrunkProgrammer](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DrunkProgrammer](https://discussions.unity.com/u/DrunkProgrammer)
#### Post date: [October 7, 2015, 7:01pm UTC](https://discussions.unity.com/t/raycast-problem/600589/7 "2015-10-07T19:01:46Z")

</div>

I copied the code to another script but I get the same error also I have the default settings of unity and the script’s extension is .cs

---

<div class="post-metadata">

### Author: ![StarManta](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/starmanta/32/280327_2.png) [@StarManta](https://discussions.unity.com/u/StarManta)
#### Post date: [October 7, 2015, 7:06pm UTC](https://discussions.unity.com/t/raycast-problem/600589/8 "2015-10-07T19:06:33Z")

</div>

Well… you appear to have actually uncovered a bug in Unity. Before you do anything else, submit a bug report with this project file.

And I’m not sure what else the rest of us will be able to say to help in this scenario - you have a situation I haven’t ever seen, and can’t reproduce. Sorry 😕

---

<div class="post-metadata">

### Author: ![Thomas-Mountainborn](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@Thomas-Mountainborn](https://discussions.unity.com/u/Thomas-Mountainborn)
#### Post date: [October 7, 2015, 8:11pm UTC](https://discussions.unity.com/t/raycast-problem/600589/9 "2015-10-07T20:11:44Z")

</div>

> [@DrunkProgrammer](#):
>
> I copied the code to another script but I get the same error also I have the default settings of unity and the script’s extension is .cs

Do you get the error with any other scripts / projects? Maybe something broke in your Unity install. If you do get the error with other files as well, it might be worth trying a clean install of Unity.

---

<div class="post-metadata">

### Author: ![HiddenMonk](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@HiddenMonk](https://discussions.unity.com/u/HiddenMonk)
#### Post date: [October 8, 2015, 4:16am UTC](https://discussions.unity.com/t/raycast-problem/600589/10 "2015-10-08T04:16:22Z")

</div>

Theres some info of this issue here [How to fix Script? error CS1525: Unexpected symbol `Internal' - Questions & Answers - Unity Discussions](http://answers.unity3d.com/questions/414792/how-to-fix-script-error-cs1525-unexpected-symbol-.html)

I am pretty sure I got this error in the past when I copied someones code on the forums that didnt use code blocks. The only solution for me was to rewrite it.

That thread talks about how there were strange symbols hidden in the text. You probably copied that code and it isnt converting properly.
