Пример #1
0
        private void Update()
        {
            if (!enableRain)
            {
                return;
            }

            if ((Time.time - lastBunnyTime) > (1 / rigidBodiesPerSecond))
            {
                Vector3 pos = new Vector3(0, 0, 0);

                pos.x = startAreaOfRain.center.x + UnityEngine.Random.Range(-startAreaOfRain.width / 2, startAreaOfRain.width / 2);
                pos.z = startAreaOfRain.center.y + UnityEngine.Random.Range(-startAreaOfRain.height / 2, startAreaOfRain.height / 2);
                pos.y = fromHeight;

                GameObject go = BSphere.CreateNew(pos, UnityEngine.Random.rotation);

                BSphere sphere = go.GetComponent <BSphere>();

                sphere.meshSettings.radius = 5.0f;
                sphere.BuildMesh();

                go.GetComponent <BRigidBody>().mass = 50;

                //randomize color for effect
                go.GetComponent <MeshRenderer>().material.color =
                    new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));

                Destroy(go, lifetime);

                lastBunnyTime = Time.time;
            }
        }
Пример #2
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if ((Time.time - lastShotTime) < (1 / maxShotsPerSecond))
                {
                    return;
                }

                Vector3    camPos = Camera.main.transform.position;
                Quaternion camRot = Camera.main.transform.rotation;

                GameObject go = BSphere.CreateNew(camPos + new Vector3(0, 0, 2), camRot);

                BSphere bs = go.GetComponent <BSphere>();
                bs.meshSettings = meshSettings;
                bs.BuildMesh();

                lastShotTime = Time.time;

                //linVel.Normalize();
                BRigidBody bRb = go.GetComponent <BRigidBody>();
                bRb.mass = mass;

                BulletSharp.RigidBody rb = (BulletSharp.RigidBody)bRb.GetCollisionObject();

                rb.LinearVelocity             = (Camera.main.transform.forward * shootBoxInitialSpeed).ToBullet();
                rb.AngularVelocity            = BulletSharp.Math.Vector3.Zero;
                rb.ContactProcessingThreshold = 1e30f;

                go.GetComponent <MeshRenderer>().material.color =
                    new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));

                Destroy(go, lifeTime);
            }
        }