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. 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. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |