- Home /
Instantiate object inside outher game object and destroy object
Hello people.
First sorry for my english, I'm now learning to write in English.
Well I'm working on a project for a shooter, and I want to make the trade in arms, in the style of CS, where the player presses the number 1 and 2, and will switch weapons, the problem is that guns should be desntro object created from my camera to suffer the rotation of the camera made by script, I tried to create the object and then sends it into the camera with the following code:
GameObject.Instantiate (mark23, armorSpawn.position, armorSpawn.rotation); mark23.transform.parent = cameraPlayer.transform;
However it did not work well.
And another question, when the following exchange of gun would be to make it deletes the weapon you had before and create the new, put this problem in giving time to delete. Following is the complete code to facilitate:
if (Input.GetKeyDown (KeyCode.Alpha1)) { numArmor = 1; armor = false; } if (Input.GetKeyDown (KeyCode.Alpha2)) { numArmor = 2; armor = false; }
if (numArmor == 1)
{
if (armor == false)
{
GameObject.Instantiate (mark23, armorSpawn.position, armorSpawn.rotation);
mark23.transform.parent = cameraPlayer.transform;
markone = true;
armor = true;
if (sigOn == true)
{
GameObject.DestroyImmediate (sig552, true);
sigOn = false;
}
}
if (Input.GetMouseButtonDown (0))
{
Rigidbody GameObject.Instantiate b = (markShoot, markSpawn.position, markSpawn.rotation) the Rigidbody;
b.AddForce (markShootForce b.transform.forward *);
}
}
if (numArmor == 2)
{
if (armor == false)
{
GameObject.Instantiate (sig552, armorSpawn.position, armorSpawn.rotation);
sigOn = true;
armor = true;
if (markone == true)
{
GameObject.DestroyImmediate (mark23, true);
markone = false;
}
}
if (Input.GetMouseButtonDown (0))
{
Rigidbody GameObject.Instantiate b = (sigShoot, sigSpawn.position, sigSpawn.rotation) the Rigidbody;
b.AddForce (sigShootForce b.transform.forward *);
}
}
The way it's done, it did not work properly, it does not delete the previous weapon.
I look for help, thank you.
anybody can answer my question? plz i need so help
Your answer
Follow this Question
Related Questions
How to Instantiate prefab as child? (Java) 1 Answer
Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 1 Answer
Instantiated object not receiving value from parent class 2 Answers
Trying to instantiate prefabs to a parent object with C# script. 1 Answer
[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer