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(); } // 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().velocity = Vector3.up * this.speed; } } } private void OnCollisionEnter(Collision collision) { if (collision.transform.tag == "Ground") { this.isJumpping = false; } } }