1

I am learning Unity. Working through the rollaball tutorial, I have come as far as video 8, where I add the line "public float speed=0;" this reveals what I already suspected, namely that in some way my script does not "take" in the unity editor.

I use Visual Studio code as my normal editor. I told Unity that it is going to be my editor for scripts. In this tutorial, I started by pressing a "new script" button as recommended by the tutorial, and created the file PlayerControl.cs in the editor. However, as the screenshot shows, the editor doesn't look like it has really taken possession of edited script, and it certainly hasn't added "speed" as a visible field. Besides which, nothing that I try will actually move the ball.

  1. Okay, so my Unity install is brand-new, and I can easily believe that I might have missed a bit. But where to look, how to diagnose? Is there a log file I should be looking at?

  2. The meaning of the OnMove method is not entirely clear from documentation that I can find. Is it called when the mouse moves? If so, it too is being unresponsive.

enter image description here

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

public class PlayerControl : MonoBehaviour {
    public float speed = 0;
    private RigidBody rb; // so Inspector doesn't see it
    private float movementX, movementY;

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

    void OnMove(InputValue mvt)
    {
        Vector2 movementVector = mvt.Get<Vector2>();
        movementX = movementVector.x;
        movementY = movementVector.y;
    }

    void FixedUpdate()
    {
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);
        rb.AddForce(movement * speed);
    }
}
1
  • Are you sure you didn't forget to save the file? I know it sounds kind of obvious but it happens a lot by mistake. Additionally, do you see a loading bar in the bottom right when you make a change? Since that shows that Unity is recompiling your code. Commented Jan 2, 2023 at 15:31

1 Answer 1

0

I don't know whether you have installed the visual studio code package or not. This is required to correctly integrate VS Code and Unity.

Just try saving the script again and return to Unity. Unity should now refresh and recompile the script into assembly then there will be the change reflected in editor.

And for the part where you can't understand OnMove() that explanation is as follows:

Since you are using Unity's New Input System, you would have created an action map. Unity will automatically call functions for each action in Action Map which is named [On + ActionName] OnMove() in all scripts. Since, the Behavior in PlayerInput Component is Set to Send Messages.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.