Trying to make a basic crouch script

I’ve been playing around with how to make a crouch action, and I came to the conclusion that the first thing I had to do, was to make my Box Collider 2D half the original size, when I press my crouch key.

When I use the following script, I get this error message. It doesn’t recognize boxcollider, eventhough I clearly stated it as Box Collider 2D

Assets/BoxMoveCrouch.cs(27,27): error CS1525: Unexpected symbol `boxcollider’

Any help would be much appreciated.

using UnityEngine;
using System.Collections;

public class BoxMoveCrouch : MonoBehaviour {

	public float maxspeed = 10f;
	public float CrouchHeight = 10f;

	BoxCollider2D boxcollider;

	



	void Start () {


		boxcollider = BoxCollider2D;

	
	}
	

	void Update () {
		{
		if (Input.GetKeyDown(KeyCode.LeftControl)
		boxcollider = new Vector2 (boxcollider.size.x, CrouchHeight);
		}

	
	
	}

	void FixedUpdate () {

		float Move = Input.GetAxis("Horizontal");


		rigidbody2D.velocity = new Vector2 (Move * maxspeed, rigidbody2D.velocity.y);

	}
	
}

My “player” is a cube, with a boxcollider 2d and a rigidbody 2d, and that’s it.

You might want to double check your curly braces in that update function.

BoxCollider2D is a Component of your gameObject, so you need to use GetComponent, you can’t simply say “boxcollider = BoxCollider2D;”

Like this:

boxcollider = GetComponent<BoxCollider2D>();