So I’m a bit of a newbie at Unity but I’m going through the Documentation and at the section - Creating gameplay it tries to show off prefabs a bit by making you create a brick wall which I assume will be destructible.
However when I press play the brick flies down past the camera so I can’t see this brick wall. I thought to myself how about I make a lookAt function like I’ve done before.
I copied the code from the Scripting reference for the lookAt function however the camera doesn’t follow the brick as it falls down in the game world. I’m not sure why the brick is falling because it doesn’t have a Rigid Body attached to it either.
The code for the brick wall creation attached as a component to an empty game object called Blocks with the tag of my user-created tag, Wall.
#pragma strict
function Start () {
for (var y = 0; y < 5; y++) {
for (var x = 0; x < 5; x++) {
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent.<Rigidbody>();
cube.transform.position = Vector3 (x, y, 0);
}
}
}
function Update () {
}
The code attached to the main camera with the target in the inspector being Blocks.
#pragma strict
public var target: Transform;
function Update() {
// Rotate the camera every frame so it keeps looking at the target
transform.LookAt(target);
}
Thanks.