using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ladders : MonoBehaviour
{
[SerializeField]
float speed = 5;
void OnTriggerStay2D(Collider2D other)
{
other.GetComponent<Rigidbody2D>().gravityScale = 0;
if (other.gameObject.CompareTag("Player"))
{
if (Input.KeyCode W)
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, speed);
}
else if (Input.KeyCode S)
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, -speed);
}
else
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
}
}
}
void OnTriggerExit2D(Collider2D other)
{
other.GetComponent<Rigidbody2D>().gravityScale = 1;
}
}
This is wrong:
if (Input.KeyCode W)
should be:
if (Input.GetKey(KeyCode.W))
same goes for:
else if (Input.GetKey(KeyCode.S))