Hi,
I created a scene where a script attached to an empty GameObject, instances prefab's into the scene. See images. (test scene, objects will be replaced)
So far so good!. I want the objects in the scene to face the camera. These cubes will be replaced by - camera facing -billboards.
Here's the script that's attached to the empty GameObject:
var prefab : GameObject;
var gridX = 5; var gridY = 5; var gridZ = 5; var spacing = 2.0;
function Start () { for (var z = 0; z < gridZ; z++) { for (var y = 0; y < gridY; y++) { for (var x= 0; x < gridX; x++) { var pos = Vector3 (x, z, y) * spacing; Instantiate(prefab, pos, Quaternion.identity); } } } }
In the inspector I drag a prefab (cube) to it. So far so good. It creates the 3d cube grid.
I've tried several ways to have the instanced cubes oriented to the camera. The scripts work on non instanced - instanciate() - objects. Drag the prefad to the hierarchy, attach script and the object faces the cam.
The look at cam script:
var cameraToLookAt: Camera;
function Update() { var v: Vector3 = cameraToLookAt.transform.position - transform.position; v.x = v.z = 0.0; transform.LookAt(cameraToLookAt.transform.position - v); }
Q: How do I get the instanced cubes (or other prefabs) face the camera?
Thank you