Answer the question
In order to leave comments, you need to log in
How to make stairs for android using Unity2D?
Hello! I'm trying to make a ladder, but it doesn't work. Difficulties arise in the fact that this needs to be adapted for android and Input.GetAxis("Vertical") will not help. I added a few variables and added a separate button for going down the stairs, the button appears when the character comes up to the stairs. Added a few bool variables to check and set the required speed of climbing stairs for the character at the right moment, as well as set the required direction. But nothing works, the buttons either do not work when you approach the stairs, or you are pushed down, no matter which button I press now, down or up. Here is the code.
variables
[Header("Climbing")]
public bool isClimbing = false;
public bool ClimbingButtonDown = false;
public GameObject ClimbingButton;
public bool JumpButtonClimbing = false;
public float speedClimbing = 0f;
public void OnJumpButtonDown()
{
if (IsGronded == true && !isClimbing)
{
rb.velocity = Vector2.up * JumpForce;
anim.SetInteger("State", 3);
}
if (IsGronded == true && isClimbing)
{
rb.bodyType = RigidbodyType2D.Dynamic;
}
if (isClimbing)
{
speedClimbing = 12f;
}
JumpButtonClimbing = true;
}
public void OnClimbingButtonDown()
{
ClimbingButtonDown = true;
if (isClimbing)
speedClimbing = 12f;
}
public void OnClimbingButtonUp()
{
if (!isClimbing)
ClimbingButton.SetActive(false);
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.gameObject.tag == "Ladder")
{
isClimbing = true;
gameObject.GetComponent<Player>().ClimbingButton.SetActive(true);
if (JumpButtonClimbing && isClimbing && !ClimbingButton)
transform.Translate(Vector3.up * speedClimbing * Time.deltaTime * 0.5f);
if (ClimbingButton && isClimbing && !JumpButtonClimbing)
{
speedClimbing = 12f;
transform.Translate(Vector3.down * speedClimbing * Time.deltaTime * 0.5f);
}
rb.bodyType = RigidbodyType2D.Kinematic;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Ladder")
{
ClimbingButton.SetActive(false);
isClimbing = false;
rb.bodyType = RigidbodyType2D.Dynamic;
}
}
Answer the question
In order to leave comments, you need to log in
<table>
<tr>
<td colspan="2"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3" rowspan="2"></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question