Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Procedural Content Generation for Unity Game Development

You're reading from   Procedural Content Generation for Unity Game Development Harness the power of procedural content generation to design unique games with Unity

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785287473
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ryan Watkins Ryan Watkins
Author Profile Icon Ryan Watkins
Ryan Watkins
Arrow right icon
View More author details
Toc

Modular weapon scripts


Our modular weapon script will do the following three main actions:

  • The Weapon script will create the connection to the player and the weapon

  • The player will need to carry and use the weapon

  • The script will drive the scripted animation, and it will also drive the the random construction of the weapon from the weapon component

We are going to place some hooks in the class definition as empty functions that we will fill in when we have some more information. Let's take a look at the full Weapon class script that's shown in Code Snip 6.1:

1 using UnityEngine;
2 using System.Collections;
3
4 public class Weapon : MonoBehaviour {
5 
6  public bool inPlayerInventory = false;
7
8  private Player player;
9  private WeaponComponents[] weaponsComps;
10 private bool weaponUsed = false;
11  
12  public void AcquireWeapon () {}
13
14  void Update () {}
15  
16  public void useWeapon () {}
17
18  public void enableSpriteRender (bool isEnabled) {}
19
20  public Sprite getComponentImage...
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 $19.99/month. Cancel anytime
Banner background image