Question by
btnglr · Jan 15, 2021 at 06:26 PM ·
scripting problemunity 2dbeginner
Ladder script doesn't work no errors
Hello, I'm using this controller with a little double jump tweak. I was trying to write a ladder script but it doesn't work and I can't figure out why.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ladder : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
[SerializeField]
float speed = 5;
void OnTriggerStay2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
if (Input.GetKey(KeyCode.W))
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, speed);
}
else if (Input.GetKey(KeyCode.S))
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, -speed);
}
else
{
other.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
}
}
}}
Comment