I am doing the scripting tutorial for Unity and am already having trouble.
- It tells me to rename the script but I can’t figure out how to do it. I did “Save as” from the Unitron window but it doesn’t even show up when I try to attach it to the main camera.
- The script I type in doesn’t move the main camera. I’m sure it’s with the way I’m typing it in but I’m painstakingly trying to insure accuracy.
function Update () {
transform.Translate(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”));
}
I realize this question is super basic, thanks in advance for your help.
'foot
Not sure about the Unitron thing. However, to rename the script, select it in the Inspector and hit the enter key. This will make the name editable like in the Finder. Type in the new name and press enter again.
First, is it attached to the camera? If not, drag the script from the Project View (where all your assets show up) and drop it on the camera in the Hierarchy view (where the objects in your scene show up).
Second, you may need to multiply by some factor since, I believe, GetAxis() will give you a value between -1 and 1. Your camera may be moving, but not enough for you to tell.
var speedMultiplier = 10.0;
function Update () {
transform.Translate(Input.GetAxis("Horizontal") * speedMultiplier, 0, Input.GetAxis("Vertical") * speedMultiplier);
}
Thanks a bunch!!
I put in the speedmultiplier thingies and it moved. It moved really fast but I think the tutorial was able to show us how to adjust it. Thanks again.
Now the second script in the tutorial is giving me an error BCE0044; expecting an identifier, found ‘=’
Is the tutorial wrong?
Nevermind, I actually found the problem. I mistyped the code.
Well, out of three codes, two of them don’t work exactly how they’re writtin in the Scripting tutorial
I would copy and paste it but Acrobat doesn’t let you do that. If somebody has the inclination, it’s the 3rd code script, named “Switch”. Unity says it doesn’t know what Follow is in the Script.
Follow is the script created at the bottom of Page 4. Make sure you have it named Follow and it is attached to the spotlight. Also, make sure you have Switch attached to the spotlight.
I haven’t used Acrobat in a million years, but I’m pretty sure it should let you select and copy text if you use the right tool. In any case, Preview lets you do this. The only problem with Preview is that it copies some characters that Unity doesn’t like, so you have to replace the blank characters at the beginning and end of lines for it to compile.
In any case, the scripts should work fine exactly as they are written in the tutorial. If you’re getting any errors, post a picture or copy the text from the Console application (/Applications/Utilities/Console.app), and we’ll be able to help you track down the error.
GetComponent() gets a reference to an attached component. The reason it can’t find Follow is probably either because you didn’t name your second script “Follow”, or because you haven’t attached the Follow script to the object with the Switch script.
Thanks alot for the knowledge.
I’m still trying to grasp the concept of “Every single character in programing has to be EXACT.”
You know what I did wrong? When I saved the follow script, I did it like “follow”. But when I wrote the script in the tutorial, they wrote follow like “Follow” with a capital letter. And of course, that little mistake made all the difference. At least Unity told me exactly where my error was. I think once I learn more and trust the software and programming stuff, I’ll do better.
Thanks for the help Muriac and others…