Before updating to Windows 10 you may need to return your Pro license. More information here

unexpected Token error

i have no idea how to fix this... my script is:

var range: float = 5; // define the detection distance private var hit: RaycastHit;

  function Update(){
    if (Input.GetKeyDown("e")){
      var ray = Camera.main.ViewportPointToRay(Vector3(0.5,0.5,0));
      if (Physics.Raycast(ray, hit, range)){
        // check if the object hit has SoundScript.js:
        var ss: 'SoundScript' = hit.transform.GetComponent(SoundScript);
        if (ss && !audio.isPlaying){ // if so, play its sound:
          audio.clip = ss.soundFX;

whenever i try to go into play mode i get this... Assets/sound file lomg.js(9,15): BCE0043: Unexpected token: soundScript. i have been messing with it for hours but with no success, what do i do?

more ▼

asked Oct 19, 2012 at 05:41 AM

avatar image

11 12 14 17

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Well, the error tells you that the problem is on line 9 of your source code. That's the meaning of the lomg.js(9,15) in the error message. So, we've narrowed the problem down to a single line. The compiler says that it doesn't understand what soundScript is. I am guessing that your line 9 is this one:

 var ss: 'SoundScript' = hit.transform.GetComponent(SoundScript);

I don't know for sure. The compiler complains about soundScript and you only have SoundScript with a capital S. So something is wrong in your question. The use of single quotes around the variable type on that line looks wrong. The example at the bottom of this page:


shows how to use GetComponent correctly.

more ▼

answered Oct 19, 2012 at 12:35 PM

avatar image

Graham Dunnett ♦♦
27.9k 37 62 188

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 19, 2012 at 05:41 AM

Seen: 1475 times

Last Updated: Oct 19, 2012 at 12:36 PM