Adding a spawn point
Now that we have our Weapon prefab put together, we are going to need a way to get it to the player. We've already answered this problem, with the chest, in the previous chapter. We will just reuse the Chest
object to also spawn weapons as well.
Open the Chest.cs
script that's to be edited. We will want to add a variable to store a reference to our generated weapon. Add the public Weapon weapon;
variable right under our randomItem
variable. Then, we need to make some adjustments to our Open()
function, which can be seen in Code Snip 6.3:
1 public void Open () { 2 spriteRenderer.sprite = openSprite; 3 4 GameObject toInstantiate; 5 6 if (Random.Range (0, 2) == 1) { 7 randomItem.RandomItemInit (); 8 toInstantiate = randomItem.gameObject; ...
Get Procedural Content Generation for Unity Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.