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?
The hit variable needs to be passed as “out”:
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).
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.
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!
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.
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)?
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
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 
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.
Theres some info of this issue here How to fix Script? error CS1525: Unexpected symbol `Internal' - Questions & Answers - Unity Discussions
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.