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.