47
Assets/Script/cubeMove.cs
Normal file
47
Assets/Script/cubeMove.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Script/cubeMove.cs.meta
Normal file
11
Assets/Script/cubeMove.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8e418e16b0667a44a7e6c74ade047a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user