ren811

CuboScript

Nov 24th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CubeScript : MonoBehaviour {
  5.    
  6.     private float randX, randY, randZ; 
  7.     private float randForceX, randForceY, randForceZ;
  8.    
  9.     private float maxForce = 250;
  10.     private float minForce = -250;
  11.     // Use this for initialization
  12.     void Start () {
  13.    
  14.     }
  15.    
  16.     // Update is called once per frame
  17.     void Update ()
  18.     {
  19.         if (gameObject.transform.position.y <= -8)
  20.         {
  21.             randX = Random.Range(-4.8f, 4.8f);
  22.             randY = Random.Range(0.58f, 10f);
  23.             randZ = Random.Range(-4.8f, 4.8f);
  24.             gameObject.transform.position = new Vector3(randX, randY, randZ);
  25.         }
  26.     }
  27.    
  28.     void OnMouseDown()
  29.     {
  30.         randForceX = Random.Range(minForce, maxForce);
  31.         randForceY = Random.Range(minForce, maxForce);
  32.         randForceZ = Random.Range(minForce, maxForce);
  33.         gameObject.rigidbody.AddForce(new Vector3(randForceX, randForceY, randForceZ));
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment