x


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;
         audio.Play();

       }
     }
   }
 }

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

kconwaykyle gravatar image

kconwaykyle
11 11 14 16

(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:

http://docs.unity3d.com/Documentation/ScriptReference/Component.GetComponent.html

shows how to use GetComponent correctly.

more ▼

answered Oct 19, 2012 at 12:35 PM

Graham Dunnett gravatar image

Graham Dunnett ♦♦
21.3k 30 41 118

(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

By RSS:

Answers

Answers and Comments

Topics:

x4661
x3347
x49
x43
x19

asked: Oct 19, 2012 at 05:41 AM

Seen: 1095 times

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