|
Hey guys, I am having a problem getting a Javascript file to get a C# script that is on the game object. This is using #pragma strict. I already moved the C# script into the Standard Assets folder and I still get this error:
Here is the line of coding causing the problem:
I have tried all kinda of different GetComponent iterations, and I still come up with the exact same error. Thanks in advance, Jason
(comments are locked)
|
|
Mixing JS and c# is not recommended unless you keep your code interdependencies very clean. C# gets compiled first and so don't have awareness of JS scripts. Switching your code to C# is recommended. You also get extra candy like auto complete.,Mixing JS and c# is usually a nightmare. c# gets compiled first and so don't have awareness of JS scripts. So ask yourself if you want to make the effort and switch over to CS or keep banging your head.,Is switching to c# an option ? Mixing JS and c# is usually a nightmare. c# gets compiled first and so don't have awareness of JS scripts. I think mcdroid is a robot! with a bad algorithm that's repeating itself.
Jan 09 '12 at 02:46 AM
Silx
(comments are locked)
|
|
I was only able to get it working if I did one of two things: 1) Move the .js outside of standard assets and keep the C# script in the standard assets folder. (this caused more errors with objects wanting to reference the .js so this was no good. 2)I had to create a function in the seeker.cs file to do what I was doing, and use
Hope that helps someone.
(comments are locked)
|

I think it's the "as Seeker" part that's the problem, not GetComponent. Where is your Seeker class defined? (Have you tried this.GetComponent()? I don't expect it to work either, if it can't find the Seeker class, but this usage is cleaner for C#.)
Take a look in your asset folder (not in unity, use your Explorer[win] or Finder[mac]) and check the name of your C# file. It should be called "Seeker.cs". And check your C# file and make sure the class is also named "Seeker" (case sensitive!!)
@yoyo: the script above is a JS script. If using the generic version in JS you have to use GetComponent.()
I checked the location just in case, and it is correctly placed in the Standard Assets folder and the files are named correctly. I have tried the GetComponent() and it still throws the same error.
If it means anything, this is from the A* pathfinding package I installed on unity, which then I manually moved the folder into the Standard Assets folder, but it is still flagging the error.