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

public class cubeMove : MonoBehaviour
{
    public int speed = 10;
    public bool isJumpping = false;

    private Rigidbody rb;
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        moveCube();
    }

    void moveCube()
    {
        if (!isJumpping)
        {
            if (Input.GetMouseButtonDown(0))
            {
                this.isJumpping = true;
                transform.position = new Vector3(0, 1, 0);
                transform.rotation = Quaternion.identity;
                rb.AddForce(transform.up * 500);
                rb.AddTorque(Random.Range(0, 500), Random.Range(0, 500), Random.Range(0, 500));
                this.GetComponent<Rigidbody>().velocity = Vector3.up * this.speed;
            }
        }
    }


    private void OnCollisionEnter(Collision collision)
    {
        if (collision.transform.tag == "Ground")
        {
            this.isJumpping = false;
        }
    }
}
