0% found this document useful (0 votes)
41 views

Public CharacterController2D Controller

This C# script controls the movement and animation of a 2D character. It gets the character's animator and box collider components. It sets the character's run speed and handles input to control horizontal movement and jumping. Pressing the S key toggles the box collider on or off to enable or disable collisions. The animator is updated based on movement and jumping inputs.

Uploaded by

murtaza shakir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Public CharacterController2D Controller

This C# script controls the movement and animation of a 2D character. It gets the character's animator and box collider components. It sets the character's run speed and handles input to control horizontal movement and jumping. Pressing the S key toggles the box collider on or off to enable or disable collisions. The animator is updated based on movement and jumping inputs.

Uploaded by

murtaza shakir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

public CharacterController2D controller;

public Animator animator;


public BoxCollider2D bc;
public float runSpeed = 40f;

float horizontalMove = 0f;


bool jump = false;

void Start()
{
bc = GetComponent<BoxCollider2D>();
}

// Update is called once per frame


void Update()
{
if (Input.GetKeyDown(KeyCode.S) && bc.enabled == true)
{
bc.enabled = false;
} else if (Input.GetKeyUp(KeyCode.S) && bc.enabled == false)
{
bc.enabled = true;
}
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}

You might also like