Hi, currently building a project that required a cube or block to be spawn in front of the player like the Minecraft thing using FPS camera. Now I only able to spawn exactly the position of the camera which the player will stuck in the middle of the cube, I wanted it to be spawn slightly in front of where the camera is facing. Thank you.
var creation : Transform;
function Update () {
if(Input.GetButtonDown("Fire1"))
Instantiate(creation, Vector3(transform.position.x, transform.position.y, transform.position.z), transform.rotation);
}
Create a new empty game object, name
it “pos”, make it a child object of
your main camera, reset it’s
position, and then set its
z-position to 3. (make sure you do
steps in this order) Then alter your
script to say this:
var creation : Transform;
function Update () {
if(Input.GetButtonDown("Fire1"))
Instantiate(creation, transform.FindChild("pos").position, transform.FindChild("pos").rotation);
}