Sprint Script

What do you think about my scripting? I am very new to C# and scripting in general so I am trying to make my code better.

My Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {


public float walkSpeed;
public float sprintSpeed;



	// Use this for initialization
	void Start () {
		
		walkSpeed = 4f;
		sprintSpeed = 8f;
		
		
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate (walkSpeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,walkSpeed*Input.GetAxis("Vertical")*Time.deltaTime);
	
		//Sprinting
		
		if (Input.GetKey(KeyCode.LeftShift))
			
		{
			walkSpeed = sprintSpeed;
		}
		else
		
		{
			walkSpeed = walkSpeed;
		}
		if (Input.GetKeyUp(KeyCode.LeftShift))
		{
			walkSpeed = 4f;
		}
		
		
	}
}

public class PlayerMovement : MonoBehaviour
{
// you can initialize variables at their declaration
public float walkSpeed = 4f;
public float sprintSpeed = 8f;

	private float realSpeed;

	void Update()
	{
		// you can use the ternary operator in this case
		realSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed;
	}
	
	// physics (which movement is) should go into FixedUpdate
	void FixedUpdate()
	{
		transform.Translate(realSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, realSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
	}
}

I think there was also something about transform.Translate not being optimal but it should work for some quick prototyping and such.

I’ve been scripting for a good 2 years now, 4 if you count web development but I’ve got a few points to make that I hope will help you out,


Goods:

-You’re using transform.Translate to move GameObjects around

-You declare your values in the Start method.

-You use Input.GetAxis to get input for movement


Bads:
-More times than not, you’ll use physics for your player jumping and landing with rigidbodies, so if you don’t want your player to phase through walls a good thing to do is to put your translate in 110648-rigidbodysettings.png

-This is a kind of clean code thing, but don’t leave the default comments on the start and update methods

-Another clean code point is the way you position your if statements, personally (since I started programming with JavaScript) I put the brace and the parenthesis on the same line
(For Example)
[How I do it]

if(x == 0){
    //do something
}

But that’s my opinion, I’ve seen other c# and Java developers do something like:

if(x == 0)
{
    //do something
}

which is what I think you’re going for
But to me doesn’t look as clean but it’s totally up to you!

I know that you’re new so I hope this constructive criticism will help you! Ask me if you have any more questions!