using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class playercomtroller : MonoBehaviour

{

    public int life = 3;


    Rigidbody2D rigid2D;



    public float jumpforce = 340.0f;

    public float walkforce = 20.0f;

    public float maxwalkspeed = 30.0f;


    // Start is called before the first frame update


    void Start()

    {

        this.rigid2D = GetComponent<Rigidbody2D>();

    }


    public void hit()

    {

        life--;

        if (life == 0)

        {

            Dead();

        }

    }


    public void Dead()

    {

        Destroy(gameObject);

    }


    private void OnTriggerEnter2D(Collider2D collision)

    {

        if (life <= 3)

        {

            hit();

        }

    }


    


    // Update is called once per frame

    void Update()

    {


        if (Input.GetKeyDown(KeyCode.Space))

        {

            this.rigid2D.AddForce(transform.up * this.jumpforce);

        }


        int key = 0;

        if (Input.GetKey(KeyCode.LeftArrow)){ key = -1; }

        if (Input.GetKey(KeyCode.RightArrow)){ key = 1; }


        float speedx = Mathf.Abs(this.rigid2D.velocity.x);

        //플레이어 속도


        if (speedx < this.maxwalkspeed)

        {

            this.rigid2D.AddForce(transform.right * key * this.walkforce);

        }

        //최대 스피드


        if (key != 0)

        {

            transform.localScale = new Vector3(key, 1, 1);

        }

    }


}


이게 플레이어 코드

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class boxdown : MonoBehaviour
{
    GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    public void Dead()
    {
        Destroy(gameObject);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
    if (collision.CompareTag("Player"))
        {
            Dead();
        }
    }
    // Update is called once per frame
    void Update()
    {
        transform.Translate(0, -0.01f, 0);

        if (transform.position.y < -5.0f)
        {
            Dead();
        }
    }
}

이게 하늘에서 장애물 떨어지는 코드인데

플레이어 쪽은
점프한 상태에서만 이동이 되고

장애물쪽은 떨어지는 속도가 ㅈㄴ 느림