
Well, have a look at the input parameters for the overloaded method we are using one more time. Why do we even create a Quarter-whatever (Quaternion) in the first place? You must be thinking.
#Prefab ui browser manual#
In fact, even the official Unity manual says you shouldn't really deal with them unless you know what you're doing. We set the Quaternion values (which takes 4 parameters, an x, y, z and an additional w value) to zero, since they are really complex. What we are doing here is basically telling the game to generate a new fireball sprite at the exact location where the player was when they pressed the Spacebar. These three elements are the X, Y and Z coordinates of the position where the fireball is generated. Line 20: We create a new Vector3 which is composed of three elements.That means in our case, gameObject refers to our main character which is Shooting Savi. The term gameObject simply refers to whatever gameObject the script is currently attached to. Now, since we are working in a 2D environment, we simply consider any third-dimension values, that is, the Z value to be 0. Quaternion: Data related to the rotation of the gameObject in 3D space.Vector3: Where to generate the gameObject in 3D space.GameObject: The gameObject to generate.So what exactly is going on here? Well, our new overloaded method takes in three parameters: Replace the old Instantiate() method with this one in the character's script and save it: using System.Collections So, let's use the overload method instead of the default Instantiate() method. We need to capture the x, y coordinates of the main character everytime, because our character can be moved using arrow keys. If we can read these values for our main character (Shooting Savi), we can figure out the exact position of our character when the spacebar is pressed, to fire the fireball, and then we spawn a new fireball there. This property of position can be accessed by the following: // For Xīoth of these values are stored as float. Any normal gameObject has a position property, which is stored as a Vector2 for 2D elements (or a Vector3 for 3D elements). Now let's deviate from our game for a bit, and talk about the gameObject in general.

Don't worry about the Quaternion argument value, we will simply set it to 0. The above overload (variation) method takes in an instance of Object (gameObject) as an argument to generate and an instance of Vector3 as an argument to define where to generate it! Perfect. Let's scroll through the overloads to see which one we might find useful. How do we fix that? Well, let's explore the overloads (other variations of a method) of the Instantiate method, we might get some help there.Ībove is the default overload (variation) of Instantiate method that we have been using up until now. It doesn't know where to generate it, so the game simply generates it at the coordinates (0, 0), that is, the dead center of the game world. That's because we are simply telling the game to generate a fireball clone whenever you press the spacebar, that's it. The bullets are not really doing anything, just falling (you can make them stop falling by setting value of gravity property as 0, like we did before) and they always spawn in the middle of the screen, not from our lead character's hand (palm). If you save this script and attach it to your main character, you can now move him around and if you press the Spacebar, the fireballs will appear and fall down.
#Prefab ui browser code#
This is simply a combination of the code we have written for movement and instantiation so far. using System.Collections īody.velocity = new Vector2(Input.GetAxisRaw("Horizontal")*speed, Input.GetAxisRaw("Vertical")*speed) Now, we will go ahead and create a new script named Shooter. Game Objects which have a prefab existing for them will have their name written in blue. NOTE: A great way to test, if a prefab exists, is to simply look at the name of the gameObject in the Hierarchy.

Once again, drag and drop the fireball into the Hierarchy to make it an active gameObject, then drag it back into the Assets to generate a prefab out of it. Now, let's create a prefab out of that fireball.
#Prefab ui browser how to#
We already know how to do that, so we'll skip over that part. Now, let's make him move using the arrow keys. Next up, we'll give him something to shoot.

First of all, let's get our little pal into the game. Let's try firing a bullet from a player who can move. Of course, we can put instantiation to much better uses. RigidBody Movement: velocity and AddForce().Prefab Instantiation with preset Properties.
