Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning C# by Developing Games with Unity 2021 - Sixth Edition

You're reading from  Learning C# by Developing Games with Unity 2021 - Sixth Edition

Product type Book
Published in Oct 2021
Publisher Packt
ISBN-13 9781801813945
Pages 428 pages
Edition 6th Edition
Languages
Author (1):
Harrison Ferrone Harrison Ferrone
Profile icon Harrison Ferrone
Toc

Table of Contents (18) Chapters close

Preface 1. Getting to Know Your Environment 2. The Building Blocks of Programming 3. Diving into Variables, Types, and Methods 4. Control Flow and Collection Types 5. Working with Classes, Structs, and OOP 6. Getting Your Hands Dirty with Unity 7. Movement, Camera Controls, and Collisions 8. Scripting Game Mechanics 9. Basic AI and Enemy Behavior 10. Revisiting Types, Methods, and Classes 11. Introducing Stacks, Queues, and HashSets 12. Saving, Loading, and Serializing Data 13. Exploring Generics, Delegates, and Beyond 14. The Journey Continues 15. Pop Quiz Answers
16. Other Books You May Enjoy
17. Index

Shooting projectiles

Shooting mechanics are so common that it's hard to think of a first-person game without some variation present, and Hero Born is no different. In this section, we'll talk about how to instantiate GameObjects from Prefabs while the game is running, and use the skills we've learned to propel them forward using Unity physics.

Instantiating objects

The concept of instantiating a GameObject in the game is similar to instantiating an instance of a class—both require starting values so that C# knows what kind of object we want to create and where it needs to be created. To create objects in the scene at runtime, we use the Instantiate() method and provide a Prefab object, a starting position, and a starting rotation.

Essentially, we can tell Unity to create a given object with all its components and scripts at this spot, looking in this direction, and then manipulate it as needed once it's born in the 3D space. Before we instantiate...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime