I'm trying to shoot a bullet out of an empty attached to a gun. I'm using instantiate but it keeps telling me that I'm using it wrong and that it can't convert Vector3 to Quaternion in my instantiate line. What am I doing wrong?
public GameObject barrelEnd;
public GameObject bullet;
void Update ()
if (Input.GetMouseButtonDown (0))
barrelEnd.transform.rotation = Quaternion.Euler (barrelEnd.transform.rotation.x, barrelEnd.transform.rotation.y, barrelEnd.transform.rotation.z);
GameObject.Instantiate (bullet, barrelEnd.transform.position, barrelEnd.transform.forward);
barrelEnd.tranform.forward is a Vector3, you need to feed the instantiate a Quaternation, like barrelEnd.transform.rotation
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
145 People are following this question.
Trying to get objects to instantiate and move at different angles
How to move an Instantiated Object towards a moving Object?
Cant Get a Bullet to Shoot (C#)
Instantiate differents objects [C#]
Instantiate() Argument error