Don't mug the newb.

Hello all, still on my free trial here but seriously thinking about plopping down the dough. I’m freshly migrating over from that little game Second Life (if anyones even heard of it) and I’m having some troubles. I do a wee bit of content creation in SL so I thinks to myself “Why not make something that the rest of the mac community at least can enjoy?” because I dont quike have a grand to swing around.

Anywho enough rambling. Here is the problem.

Can’t add script

Can’t add script behavior _____________. The Script needs to derive from MonoBehaviour!

Even has a nice little “Ok” button, but it’s not ok. I have no fricken clue what’s wrong with it. I tried one script of my own hacking, one from the wiki, and one from an open source game that I know worked. I’m guessing that I am doing something stupid like not including another script that it’s trying to access. For reference I tried to use the one on the wiki about 2D flight controls.

Not quit following what you are trying to do, but I would suggest you start with JavaScript scripts. They automagically derive from MonoBehavior, so you just add you code. To add a JavaScript script go to Assets → Create → JavaScript. You will then have a new script call NewBehaviorScript with one funtion in it, Update(). You will want to rename this script to something that makes sense to you.

My guess you were creating a C# script. If doing that you must “inherit” from MonoBehavior. So the top of your script would be something like:

Using UnityEngine;
Using System.Collections

public class YourScriptName : MonoBehavior

Also, you need to rename your script from NewBehaviorScript to the same name as you class name, “YourScriptName” in the example above.

As I stated earlier, I would suggest starting with JavaScript since C# is much more strict and less forgiving.

If your “OK” button is a GUITexture, then attach your new JavaScript to the GUITexture (drag and drop) and add the following to the Javascript

OnMouseDown()
{
  'Do Something here'
}

The ‘Do Something here’ would be some more scripting performing some action. In the documentation, go to Script Reference, then click on the Alphabetical Reference link at the top, then scroll down to MonoBehavior. There you will see the OnMouseDown function.

Hope this helps a little.

I’ll rephrase it then. I was trying to take an existing script from the wiki to play with in the editor. I’ll check that it’s named the same as the class name.

Update: Now the error of choice, even with some javascript that I took out of an open source widget, is…

Can’t add script

Can’t add script behaviour ____________. All scripts need to successfully compile first!

Update2:

Ok changing the name of the script to the class name, removing another script that was being wierd, saving the scene, and relaunching Unity fixed that part.

Perhaps that was the only problem.

Lallander, I run into this problem once in a great while too (“The Script needs to derive from MonoBehaviour!”). And when it happens I just relaunch.

Yeah I had to rename it and relaunch, works fine now.

I did run into a new problem tho.

One of the scripts that I deleted is now generating an error.

BCE0042: Error reading from ‘Assets/playerCamera.js’: ‘File ‘Assets/playerCamera.js’ was not found.’.

But as far as I can tell nothing was ever actually using that script. How can I find out … I guess basically what part of the scene thinks it should have access to that script so I can kill it off.

Update: Bleh nevermind. I saved again and relaunched. And of course no more problem. That seems to be a recurring theme.

Having to relaunch to get a script to complile is in my opinion a bug. (Which I’ve never run into myself btw.)

If you can write up an example on how to trigger this behaviour please report it to the otee guys using the ReportBug.app. I’m sure they want to get it fixed. Normally saving in an editor should trigger (re)compilation (if the editor supports the SubEthaEdit protocol for notifying about file changes… and if not, the compilation will start when you switch from the editor back to Unity.)

You probably deleted the file through the Finder. File manipulations should be done through the Unity project view. That way unity can track file renames and deletes more reliably.