Just starting out

Hi everyone! I just started to use and learn Unity about two days ago. I spent my first two days learning my way around the editor and today I started the first tutorial beginner-roll-a-ball. I got to the third video where you create a script to move the player object. This is the code from the video:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        Rigidbody.AddForce (movement);
    }
}

I checked and rechecked to make sure everything was entered just as in the video but it does not work. The video says let’s check in Unity great no errors now let’s test it out and hit play. I can not do this. I get the following error:

Assets/scripts/PlayerController.cs(13,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’

Since I am just starting out and learning I have no idea what this means and why it works in the tutorial but not for me.

Any help would be greatly appreciated a point in the right direction!

The tutorials were made for Unity 4.x. Up until the beginning of last month that was still the latest release. They haven’t been updated yet though.

Basically the shortcuts for accessing components were removed and you need to use GetComponent. Try this at line 13.

GetComponent<Rigidbody>().AddForce(movement);

ah ok that’s cool. Replacing line 13 with what you wrote gave me two additional errors. I was looking at the scripting API for ridgidbody but I’m not sure how to use the one example they give for AddForce. I will see if I can get this working and I"m sure in time the tutorials will get updated hopefully for the new version :slight_smile:

So, just out of curiosity if the tutorials can’t help me learn scripting for Unity at the present time, how can I learn how to script for Unity in the mean time until they are updated?

I’m not aware of any issues other than those involving component shortcuts. I learned C# prior to coming to Unity so for me it was mostly a matter of learning how to navigate the editor and using the scripting reference guide as needed. I’ve only viewed a few learning section videos long enough to assist with any problems.

There is a series on CGCookie that was made during Unity 5’s beta, but it requires a paid membership.

https://cgcookie.com/unity/cgc-courses/c-bootcamp/

Some YouTube channels, like Brackeys, may have some more up-to-date videos, but I haven’t really dug around.

https://www.youtube.com/user/Brackeys

If you simply want everything to work while you pick up the basics, you could try grabbing Unity 4.x and then learn the differences later. Most of the learning section should work with Unity 4.6 and it is still receiving updates.

http://unity3d.com/get-unity/download/archive

Aside from that you could just post any errors and we can try to assist you through them.

Thanks for the reply and links I will check them out. I’m going to keep plugging along and hopefully if I’m lucky I can also find some examples in the asset store of the same type of code. That and the scripting API would help me out a lot.

I usually do a Google search with “site:docs.unity3d.com” followed by anything I’m looking for. It does the job for the most part and definitely beats trying to work through it manually. I still occasionally have to go digging if I don’t know the right terms.

http://docs.unity3d.com/ScriptReference/