C
C
crocodoctor2020-09-21 00:02:52
Unity
crocodoctor, 2020-09-21 00:02:52

How to setup crouch control in 2D Runner on Unity?

I'm new to programming, I create a runner in Unity 2D and wrote a script for crouching (changing the boxcollider)

public void CrouchControl
(bool isNado) // присед
{
if (isNado && !isCrouch)
{
isCrouch = true;
bc.offset = new Vector2(bc.offset.x, bc.offset.y - bc.size.y * (1 - koefCrouch) / 2);
bc.size = new Vector2(bc.size.x,koefCrouch*bc.size.y);
}
else if (!isNado && isCrouch)
{
isCrouch = false;
bc.offset = new Vector2(bc.offset.x, bc.offset.y + (bc.size.y /koefCrouch -bc.size.y) / 2);
bc.size = new Vector2(bc.size.x, bc.size.y/koefCrouch);
}
Далее создал скрипт для управления через GetKey который считывал нажатие:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent (typeof(PlayerController))]
public class UserControl : MonoBehaviour
{

private PlayerController pc;
// Start is called before the first frame update
void Start()
{
pc = GetComponent<PlayerController> ();
}

// Update is called once per frame
public void Update()
{
pc.CrouchControl (Input.GetKey(KeyCode.V));
}

}

Can't change control to UI Button

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question