Hellooooo again I'm trying to get my player I have moving around to actually shoot, I've had a look through the manual pages on instantiation but I'm still struggling to get it to work Code (csharp): using UnityEngine; using System.Collections; public class playerShoot : MonoBehaviour { // Update is called once per frame void Update () { Object bullet = GameObject.FindWithTag("bullet"); if(Input.GetButtonDown("Fire1")) { GameObject muzzle = GameObject.FindWithTag("Player"); Object clone = Instantiate(bullet, muzzle.transform.position, muzzle.transform.rotation); } } } I've tried replacing the "Object" lines with "GameObject" but I still can't get it to work, the error message I'm getting is: Code (csharp): NullReferenceException: The prefab you want to instantiate is null. Could someone please help as I'm still learning this scripting stuff and I've been trying all sorts for the last couple of hours and still can't get a bullet to come out My bullet prefab has a "bullet" tag on it, and I know the muzzle I'm using at the moment is just the player location as I wanted to just get something working before I juggle things around Thanks in advance for the help!
FAIL. I just tried dragging the prefab from the project into the scene and it now works! Is there a way to have it automatically pull it from the project or for things like this do you need to make sure you have the object hidden in the scene somewhere that it can instantiate from?
GameObject.FindWithTag can only return GameObjects in the scene, not prefabs in your project. You should read: http://unity3d.com/support/documentation/Manual/Instantiating Prefabs.html