So basically the procedure I’m trying is to create a box, added the “rigid body” component to it, then I created a new C# script, copied the contents of the “ShipControls” to the blank script, then associated the script to the box. Problem is when I run the game I get a “parsing error”? What am I doing wrong?
Is there a better/easier way to just add simple movement controls (in 3 dimensions)?
Second issue: Could someone explain the difference between the file menu option “new” and “new project”? I seem to be unable to start a new project. If I try to start a new project, I can create a new folder but that’s it. I can’t seem to specify the project name and the save button is greyed out.
Third issue: How do I delete an asset from the “Project” panel? I didn’t realise it at the time, but I accidently created 4 identical “NewBehaviourScripts”.
I’m liking somethings about Unity, but some other things seem a bit less than intuitive…
Are you sure you created a C# script and not a JavaScript?
Also when creating C# scripts you must make sure that the name of the class is the same as the name of the script.
You have to type the name of the project in the project directory field. Or Click on Set, where you can then choose a folder and enter the name of the project in the text field.
New will create a new scene. New Project creates a new project. A project is a collection of scenes assets making up your entire game. A scene is more like a level.
Select the script and choose Edit → Delete from the menu. Or just cmd-delete.
Ok, I renamed the resource to ShipControls and it now appears as ShipControls.cs in the assets.
I’ve since closed that project (without saving it) and am starting a new scene. I followed the same procedure as before (create box, add rigid body) and “ShipControls” already appears in my project panel. If I try to drag “ShipControls” to my box I get this error:
Can't add script behaviour ShipControls. The script needs to derive from MonoBehaviour!
And yet ShipControls doesn’t appear in my components. I must be missing some real basic concept here, what I’m I doing wrong?
Hmmm… I’m missing something here. I’ll experiment with this more.
Duh! :roll: I tried right clicks and the delete button (habits from the Windoze world), Ok got it.
The script can only appear in the component menu once it has successfully compiled. You can see all compile errors in the console or by clicking in the status line at the bottom of the main window. You can also double click on it, which will get you to the error in the script.
So the question is why does the script not compile? It worked fine for me. So maybe a copy paste error. Or there is another script which has some compile errors in the project. Double clicking on the first error in the console gets you to the error in the script.
Anyway, easiest thing is to start over.
Create a new project.
Copy the script i attached to this post into the assets folder. Wait until compilation has finnished. (The grey spinning bar in the right corner)
Then drag it onto a cube.
And you should have your cube spaceship going already.
Yes, I think that’s what it was because the script you posted worked fine. I copy and pasted from the Wiki to “TextWrangler” then copy and pasted to the Unity editor. Looked like there were some “funky characters” in the Inspector preview, but nothing in the editor. I’m thinking that was the problem.
Unrelated but another Noob question: How do I rotate an object around the “Y” axis from the “top” view in Unity’s editor using a mouse? The “rotation” widgets are a bit non-standard and it doesn’t appear possible to rotate using the Widgets when directly above an axis.
Btw. Unity has a builtin text editor with full syntax highlighting.
TextWrangler is really not very well suited for scripting in Unity. I’d suggest you either use the builtin one or pick a good one, like subetha edit or textmate. But please save yourself the trouble of going with TextWrangler.
Hmm… would be nice if it were a bit more like other apps, would be easier to use also.
Sounds like good advice. I picked up TextWrangler based on a thread posted here, but I can see it’s not for me. I’ll stick with Unitron for now.
Now that I’ve got the ShipControls script working, it’s pretty nifty. Is there something similar available for maneuvering a vehicle in all 3 dimensions?
I did a bit of experimenting with hinges, springs and gravity this morning. I can already see potential for some very interesting sims…
Thanks for your help Joachim. It’s so nice to get such fast answers to questions!
I’m working on a vehicle that floats in space connected to a tether. I’ve assembed the tether out of long boxes connected with hinges and am using the ShipControls script to move the vehicle. I’ve roughed out the basics in just a few hours, including my time on the forum this morning. Not bad for a first attempt at a fairly complex physics problem with Unity.