Unity doesn't accept my scripts, help

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

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

rigidbody.AddForce(movement);
}
}

this is how i put it but unity says this:

“Expression denotes a ‘type’,where a ‘variable’, ‘value’ or ‘method group’ was expected”

and this:

“The best overloaded method match for `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)’ has some invalid arguments”

and this:

“Argument #1' cannot convert object’ expression to type `UnityEngine.Vector3’”

please help i’m new to scripting.

Please use code tags when posting code.

When creating a C# script, it should look like this:

using UnityEngine;
using System.Collections;

public class ClassName : MonoBehaviour
{
    // Your code goes here
}
1 Like

you’re lacking a semicolon after this line: Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical)

1 Like

What the two above said is your issue.

So, when the compiler finds a problem with your code it emits 4 pieces of information:

a) An error number
b) The line number where the problem happened
c) The column where the problem happened
d) A textual description of the error.

New scripters tend to only focus on the (d). That textual description can be a little misleading, so I’d recommend:

  1. Double-click on the error, which should take you to the line in the script with the problem. If that doesn’t work, simple switch to your text editor and find the line number. It’s the one after the opening bracket.

  2. Review the code, and see if you can find any problems. It can happen that the line that gets reported is after where the real problem happened. So you should look at the specific line, and lines before.

  3. Visit Answers and search for the error number. There are many thousand of questions about the many error numbers. For example, I believe your error number is cs0119. Searching for that on Answers gives you:

http://answers.unity3d.com/questions/topics/cs0119.html

If you look at the number of views those pages have, you’ll see that around 100,000 people have used Answers for help with this error. So it’s pretty usual to use that site for help.

Sorry I’m new to the forum too… This is the entire script

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, 0f, moveVertical);

        rigidbody.AddForce (Vector3);
    }
}

Still got these errors

Okay, corrected these erros it was the capital letter on Rigidbody.AddForce

But I got a new error:

An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’

And I didn’t find anything on the forum.

AddForce (movement)
NOT
AddForce (Vector3)
:slight_smile:

Also, it should be rigidbody. Lowercase R

Thanks, both answers made it work!! I had put a lowercase r but it was giving me 3 different errors, it was because of the Vector3.

I suggest looking up how classes work. Maybe you won’t get errors like that again :slight_smile:

Haha it looks like you have no idea as to what you’re doing. I highly suggest you to watch the tutorials made my Unity and refer to the Unity documentation.

Best sources of info.

Good luck.