I have another question
When the Objects are spawning, they spawning only on the same place, but I want that when I am moving they should spawn at the new position in front of me ( forward * 10):
if (Input.GetButtonDown(“SetCubeRed”)) // see Input SetCubeRed
{
Instantiate(CubeRed, transform.position, transform.rotation); // spawn Red Cube
transform.TransformDirection(Vector3.forward * 10);
}
Please help me again^^
this is how Instantiate looks API wise:
Instantiate (original : Object, position : Vector3, rotation : Quaternion)
so you have the object, in your case CubeRed , then you set the position of where it is suppose to spawn in your case transform.position …
You dont want that do you, so change the transform.position to:
(transform.position+Vector3.forward*10) and it will be spawned 10 units in front of you.
I tested this but now the Cube spawn only at the same position as before. Do you can write the complete code please?^^
But thanks for your help;)
If you are unable to implement the script based on an answer as complete as the one you just got, I would suggest you go through some scripting tutorials before proceeding.
I am able to implement the script but it does not work. The Object spawn at the same position as before.
So I think I understand something wrong and ask him to write the script^^
Please help me xD
var SetCubeRed : Transform;
if (Input.GetButtonDown("SetCubeRed")) {
// Instantiates 1 copy of the assigned variable SetCubeRed in front of you.
Instantiate (SetCubeRed, (transform.position+Vector3.forward*10), transform.rotation);
This should give you what you want, just save as a javascript file, and attach to the Main Camera.
Thanks for your script, but it does work the same as my script xD
"This should give you what you want, just save as a javascript file, and attach to the Main Camera. "
I forgot to attach my script to my Player and so the gameobject spawn only one time when the player spawn xDDDDDDDDD
Thanks for this sentences 