Updating old movement script

Hello,
I had a script working back in the old version of Unity but now I’m using Unity 5.5 and I can’t figure out how to get my script to work. All this code did was move an object forward at a constant rate.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class PlayerMover : MonoBehaviour {

    public int speed;
    public int fSpeed;
    public int rSpeed;
    Event onClick;
    float buttonMove = 0;

    void FixedUpdate()
    {
        MovePlayer (Input.GetAxis ("Horizontal"));
        MovePlayer (buttonMove);
    }


    void MovePlayer(float horizontal)
    {
        float rotatePlayer = horizontal;
       
        transform.Rotate(new Vector3(0, 0, rotatePlayer) * rSpeed);
       
        Vector3 movement = new Vector3 (0.0f, 0.0f, fSpeed);
        rigidbody.velocity = movement * speed;
    }

    public void StartMove(float horizontal)
    {
        buttonMove = horizontal;
    }
}

Is anything calling StartMove()? Put a breakpoint in it or a debug.log in it and see if someone is calling that. Otherwise buttonMove would be zero.

the part that is not working is the rigidbody movement.

I suggest you start sticking Debug.Log() calls in at various places to display some of your values, see if they are what you expect. Things like velocity and movement and speed might be a great place to start looking.

Silly question, but do you have a rigidbody on the player? Are null exceptions being thrown?

Also, rigidbody is deprecated. I’d encourage you to use GetComponent instead before Unity takes it out altogether.

Good catch @BlackPete … Pretty sure it doesn’t even compile anymore. Maybe OP is just copy/pasting this code, in which case yeah, GetComponent() is gonna be necessary instead of ‘rigidbody’