Untitled

 avatar
unknown
plain_text
a year ago
991 B
3
Indexable
public float speed = 20.0f;
    public float jumpForce = 300.0f;

    private bool canJump = true;

    // Update is called once per frame
    void Update()
    {
        transform.Translate(0, 0, speed * Time.deltaTime);
        if (Input.GetKey("a"))
        {
            transform.Translate(-5 * Time.deltaTime, 0, 0);
        }
        if (Input.GetKey("d"))
        {
            transform.Translate(5 * Time.deltaTime, 0, 0);
        }

        if (canJump && Input.GetKeyDown("space"))
        {
            canJump = false;
            this.GetComponent<Rigidbody>().AddForce(new Vector3(0, jumpForce, 0));
        }
        if(transform.position.y < 0)
        {
            transform.position = new Vector3(0, 1, 1);
        }

    }

    void OnCollisionEnter(Collision collision)
    {
        canJump = true;
        if(collision.gameObject.tag == "obstacle")
        {
            transform.position = new Vector3(0, 1, 1);
        }
    }
Editor is loading...
Leave a Comment