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.
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?
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.
- Tutorial: https://learn.unity.com/tutorial/moving-the-player?uv=2020.2&projectId=5f158f1bedbc2a0020e51f0d#
- System: Mac OS 11.6
- VS Code 1.74.2
- Script code is below
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);
}
}
