Hi all,
How do i make a cube generating object that generates the cube with some velocity and then drops to the ground.
Particle emitter is not functioning accordingly
Thanks
Hi all,
How do i make a cube generating object that generates the cube with some velocity and then drops to the ground.
Particle emitter is not functioning accordingly
Thanks
You should make a prefab of a cube with a rigidbody, and instantiate it (and add velocity to it) in a script.
yes this is what i am doing but i am looking for automatic constant generation of this prefab just like particle system
Here is something…
using UnityEngine;
using System.Collections;
// put this on a game object located where you want the cubes to appear
public class SprayCubes : MonoBehaviour
{
public float interval = 1.0f;
IEnumerator Start()
{
while(true)
{
GameObject cube = GameObject.CreatePrimitive( PrimitiveType.Cube);
cube.transform.position = transform.position;
cube.transform.localRotation = Quaternion.Euler(
Random.Range ( 0.0f, 360.0f),
Random.Range ( 0.0f, 360.0f), 0);
Rigidbody rb = cube.AddComponent<Rigidbody>();
rb.velocity = new Vector3(
Random.Range ( -5.0f, 5.0f),
Random.Range ( 0.0f, 10.0f),
Random.Range ( -5.0f, 5.0f));
rb.angularVelocity = new Vector3(
Random.Range( -10.0f, 10.0f),
Random.Range( -10.0f, 10.0f),
Random.Range( -10.0f, 10.0f));
yield return new WaitForSeconds( interval);
}
}
}
thanks but its not working i attached it to empty game object ;/ no luck
I just tested it, it works fine. I made a blank project, put GameObject at position = (0,0,0), add a directional light, attached the SprayCubes script (as copy-pasted from the above forum post!) and there were cubes spraying onto my screen.
Entire .unitypackage of the above test is attached herein
2107369–138140–SprayCubes.unitypackage (5.03 KB)
thank you i dont know why it didnt worked before but working well now thanks