Why my player controller for c# can't move?

I have a javascript player controller that works.

#pragma strict

//For player movements
var speed : float = 4;
var jumpHeight : float = 5;
var superSpeed : float = 10;
var superSpeedTime : float = 5;



//The players amount of health
//var health : int = 5;


//var target : GameObject;
private var lockCursor : boolean  = true;

//To adjust the speed of the player
private var superSpeedOn : boolean = false;
private var superSpeedElapsed : float = 0;




	function Awake ()
	{
		Screen.lockCursor = lockCursor;
	}

	function OnDisable()
	{
		Screen.lockCursor = false;
	}
	
	function Update()
	{
	
		if (Input.GetMouseButtonUp(0))
		{
			Screen.lockCursor = lockCursor;
		}
	}

function FixedUpdate () {

//Handles the horizontal movement of the player
rigidbody.velocity.x = speed * Input.GetAxis("Horizontal");



if(superSpeedOn == true){

rigidbody.velocity.x = superSpeed * Input.GetAxis("Horizontal");


//Add to elapsed time
superSpeedElapsed += Time.fixedDeltaTime;

//Check if enough time has passed
if(superSpeedElapsed >= superSpeedTime){
superSpeedOn = false;

}


} else {


rigidbody.velocity.x = speed * Input.GetAxis("Horizontal");
}




//Handle the jumping of the player
if( Input.GetButton("Jump") && IsGrounded() ){
rigidbody.velocity.y = jumpHeight;
}


//Check if we are hitting the sides of an object
var distance : float = rigidbody.velocity.magnitude * Time.fixedDeltaTime;	
var hit : RaycastHit;

if (rigidbody.SweepTest(rigidbody.velocity, hit, distance)){

//Stop moving!
rigidbody.velocity.x = 0;


}


}


function IsGrounded (){

//Fire a raycast to check for the ground
return Physics.Raycast(transform.position, Vector3.down, collider.bounds.extents.y + 0.01);
}

/*

function Hit (){
//Remove one hit point and check if we're dead. 
health -= 1;
if(health == 0){	
Debug.Log("You died!");
Destroy(gameObject);
}

}

function OnCollisionEnter(collision : Collision ){

//Check if we hit an object that can hurt me
if(collision.gameObject.tag == "Hurt")
Hit();


}
*/

/*function SuperSpeed () {

//Turn on superspeed!
superSpeedOn = true;
superSpeedElapsed = 0;
}*/

But my C# player controller has no errors but doesn’t even budge at all?

using UnityEngine;
using System.Collections;

public class PlayerControlC : MonoBehaviour {


    float speed = 4f;
    float jumpHeight = 5f;

    private bool lockCursor = true;

    void Awake()
    {
        Screen.lockCursor = lockCursor;
    }

    void OnDisable()
    {
        Screen.lockCursor = false;
    }

	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonUp(0))
        {
            Screen.lockCursor = lockCursor;
        }
	}

    void FixedUpdate()
    {
        //Handles the horizontal movement of the player
        bool isGrounded = Physics.Raycast(transform.position, Vector3.down, collider.bounds.extents.y + 0.01f);
        Vector3 velocity = rigidbody.velocity;
        velocity.x = speed * Input.GetAxis("Horizontal");
        
        //Handles the jumping of the Player
        if (Input.GetButton("Jump") && isGrounded == true)
        {
            velocity.y = jumpHeight;
        }

        //Check if we are hitting the sides of an Object
        float distance = rigidbody.velocity.magnitude * Time.fixedDeltaTime;
        RaycastHit hit;
        if (rigidbody.SweepTest(rigidbody.velocity, out hit, distance))
        {
            //Stop moving!
            velocity.x = 0f;
        }
    }

/*    void IsGrounded()
    {
        //Fire a raycast to check for the ground
       // Physics.Raycast(transform.position, Vector3.down, collider.bounds.extents.y + 0.01f);
    }*/
}

When you assign the rigidbody velocity to a temporary variable, because in C# Vector3s are value types, it COPIES the values into a NEW OBJECT.

Therefore, when you change the x value (or the y value, for that matter) of the copy, it doesn’t affect the original object.

Try replacing velocity with rigidbody.velocity everywhere in FixedUpdate and see if that fixes the problem.

“In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don’t set the velocity of an object every physics step, this will lead to unrealistic physics simulation. A typical example where you would change the velocity is when jumping in a first person shooter, because you want an immediate change in velocity.”

also its unlikely that you will be able to directly modify one part of the rigidbody.velocity vector3. if you must use velocity you should use something like

rigidbody.velocity = new Vector3(velocity.x,0,0);

this is also true of many other variables.