Bombs dropping
Hi everyone i'm making a fighter aircraft and i need to make bombs but all the current scripts are for spawning an object at a certain position. I can easily place a rigidbody on the bombs to make it fall and use ontriggerenter to destroy the bomb and make an explosion but how do i spawn an object at the player's current position by pressing "B"?
"how do i spawn an object at the player's current position by pressing "B"? "
You need to get familiar with Unity basics - learn how to read and set GameObject Transform and position.
Also, just google for: "unity spawn an object at the player's current position"
- You'll get multiple hits.
Answer by MT369MT · Sep 01, 2018 at 01:08 PM
Hi, you should use something like this:
public GameObject Bomb;
public GameObject Player;
void Start()
{
Player = GameObject.Find("Player");
}
void Update()
{
if (Input.GetKeyDown("b"))
{
Instantiate(Bomb, Player.transform.position, Quaternion.identity);
}
}
I tried that EXACT script yesterday but it didn't work :(
Are you sure that you assigned the Bomb prefab in the inspector and that your player is named Player?