Scripts Won't Run/ no bug just won't run (New to Unity)

Hello guys

I’m just following Roll a ball tutorial and everything seem fine but when i write the script it won’t play

Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
public float speed = 0;

private Rigidbody rb;
private float movementX;
private float movementY;

// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

void Onmove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get();

movementX = movementVector.x;
movementY = movementVector.y;
}

void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);

rb.AddForce(movement * speed);
}
}

Visual studio show that there is no problems detected as well as Unity
But when I click play it just won’t move
When i add speed the speed also show in the player inspector but no matter the number i put it
It just won’t move

This is my first time using Visual Studio and Unity as well as first time trying to run C# on Unity
I follow every step of the tutorials
My Unity version is 2020.3.19f1

You have to be very careful when following tutorials to follow spelling accurately. It’s very easy to miss typos in code if they don’t result in an error.

Onmove should be OnMove

If you have more questions and need to post code, you can use code tags in this forum to make it easier for people to read your code and help.

Good luck, and keep at it!

1 Like

Maybe I am reading this wrong, but I do not see OnMove or Onmove being called anywhere!

I think this is using the new Unity Input system, where you set up actions in the editor.

void Onmove(InputValue movementValue) needs to be void OnMove(InputValue movementValue)

Like said above you have to be exact when it comes to spelling and capitalization. Do you have the assistance turned on where it shows various colors depending on what the item you are typing is?

1 Like

I fix Onmove to OnMove but still when i click play nothing happen, it won’t move.
Also wonder even when i do the wrong spelling it doesn’t show up in visual studio, not sure where to fix
Can u guys help me check where this went wrong? been stuck here for a while now

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public float speed = 0;

    private Rigidbody rb;
    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
       rb = GetComponent<Rigidbody>();
    }

    void OnMove(InputValue movementValue)
    {
        Vector2 movementVector = movementValue.Get<Vector2>();

        movementX = movementVector.x;
        movementY = movementVector.y;
    }

    void FixedUpdate()
    {
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);

        rb.AddForce(movement * speed);
    }
}

Watch through each step of the tutorial again - you are missing something that is required for it to work.

Do you have a Player Input component attached to your game object? And have you created Input Actions?

It looks like that’s covered in video 4 of that tutorial.

In the text for that step it says:

Have you done that?

Yes! I was having this problem when I first started as well and then finally figured it out about 2 days after starting Unity. It is a game changer. https://docs.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=windows

This will come with intellisense as well which will make looking over your code much easier.

Now you should see red underline squiggles, different color on words depending on what they are. And a dropdown menu when typing out known words that can help you go faster. Pressing tab with that drop down will select the first one on the list and auto complete it.