I’m currently working on first person shooter mechanics, but I’m trying to make it as portable as possible (ideally with the ability to drag and drop the script onto an empty GameObject and have it work. I’ve been doing this by checking if a component is null, e.g. rigidbody. If it’s null then I create the component and set some default attributes to it. This all works until I try to make the bullet that will be fired.
Essentially what I’m trying to do is create a prefab within a script that I can instantiate at a later point in time. This “projectile” object will just be a basic sphere. I have tried using GameObject.CreatePrimitive(), but this generates it. How would I go about creating a GameObject from inside a script without instantiating it?
This is what I currently have but it instantiates a projectile.
`if(projectile == null)
transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);