Search Unity

PlayerController error

Discussion in 'Scripting' started by kvsp3r, Aug 5, 2020.

  1. kvsp3r

    kvsp3r

    Joined:
    Mar 17, 2018
    Posts:
    2
    I'm new to Unity and I'm trying to do the Roll The Ball tutorial. I wrote the script exactly as shown in the video but when I try to go to play mode it says "All compiler errors have to be fixed before you enter play mode". Can someone tell me what is wrong with my code?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class PlayerController : MonoBehaviour
    7. {
    8.     private Rigidbody rb;
    9.     private float movementX;
    10.     private float movementY
    11.    
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         rb = GetComponent<Rigidbody>();
    16.     }
    17.  
    18.     void OnMove(InputValue movementValue)
    19.     {
    20.         Vector2 movementVector = movementValue.Get<Vector2>();
    21.  
    22.         movementX = movementVector.x;
    23.         movementY = movementVector.y;
    24.     }
    25.  
    26.     void FixedUpdate()
    27.     {
    28.         Vector3 movement = new Vector3(movementX, 0.0f, movementY);
    29.        
    30.         rb.AddForce(movement);
    31.     }
    32. }
    33.  
     
  2. kvsp3r

    kvsp3r

    Joined:
    Mar 17, 2018
    Posts:
    2
    Disregard my original post, I was missing a ; after private float movementY. The issue now is my player isn't moving at all.
     
  3. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    so to help you out, we need the script error you get ,

    ""All compiler errors have to be fixed before you enter play mode" means only that you got errors and that you cannot start before you fix them, therefore we need those errors written in your console to help you out,

    your character is not moving becouse you have a function "OnMove" which you appearently never call anywhere :eek:
     
  4. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481