I’m following a course over at digital tutors C# for unity and I’m having problems with the script. I’m not getting any errors at all but it is not doing what it is supposed to do. Nothing happens when I push the spacebar or I. Here is the script any help would be greatly appreciated.
using UnityEngine;
using System.Collections;
public class Lesson_10 : MonoBehaviour
{
public int weapon = 0;
private string weaponName = null;
private string addedItems = null;
//public int inventorySpace = 5;//Variable that specifies number of elements in inventory list
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyUp (KeyCode.I)) //Checks what is in the inventory when I is pressed
{
CheckInventory(addedItems);
}
if (Input.GetKeyUp (KeyCode.Space)) //Waits for player to press space and performs the method generating a random number each time space is pressed
{
WeaponSearch ();//This is a method/funcion call
}
}
void CheckInventory(string addedItems)//Creates inventory and places some items inside.
{
string [] inventory = new string[5]{"Ripped Tunic", "Old Boots", "Dagger", "Gold Ring", "null"};//Declares inventory list and what is in each slot
foreach (string items in inventory) //Cycles through inventory
{
inventory[4] = addedItems;
Debug.Log(items);
}
}
void WeaponSearch()//This is a method/function definition
{
weapon = Random.Range (1, 5);//Generates random number between 1 and 5
switch (weapon)
{
case 1:
weaponName = "Sword";
UpdateInventory(weaponName);
break;
case 2:
weaponName = "Axe";
UpdateInventory(weaponName);
break;
case 3:
weaponName = "Bow";
UpdateInventory(weaponName);
break;
case 4:
weaponName = "Dagger";
UpdateInventory(weaponName);
break;
default:
Debug.Log("You need a weapon!");
break;
}
}
void UpdateInventory (string weaponName)//Takes the names of the weapons
{
addedItems = weaponName;
CheckInventory (addedItems);
}
}