Hello all. I am using the Brackeys Inventory System for my project. However, I attempted to modify the health potion item into a magical scroll that fires a projectile and is then removed, similar to a consumable. This did not return errors, however does not have any effect whatsoever. And just to point out, I may be missing something, since this script is in JavaScript and I am only fluent in C#, however I do not have the time to convert the whole project.
Here is my (modified) code:
#pragma strict
//This script allows you to insert code when the Item is used (clicked on in the inventory).
var deleteOnUse = true;
var fireparticle : GameObject;
var lightningparticle : GameObject;
var iceparticle : GameObject;
var arcaneparticle : GameObject;
private var playersInv : Inventory;
private var item : Item;
@script AddComponentMenu ("Inventory/Items/Item Effect")
@script RequireComponent(Item)
//This is where we find the components we need
function Awake ()
{
playersInv = FindObjectOfType(Inventory); //finding the players inv.
if (playersInv == null)
{
Debug.LogWarning("No 'Inventory' found in game. The Item " + transform.name + " has been disabled for pickup (canGet = false).");
}
item = GetComponent(Item);
}
//This is called when the object should be used.
function UseEffect ()
{
if(this.gameObject.CompareTag("HP")) {
addHealth();
}
if(this.gameObject.CompareTag("FireballScroll")) {
Instantiate(fireparticle);
}
// if(this.gameObject.CompareTag("LightningballScroll")) {
// addHealth();
// }
// if(this.gameObject.CompareTag("IceballScroll")) {
// addHealth();
// }
// if(this.gameObject.CompareTag("ArcaneballScroll")) {
// addHealth();
// }
//Play a sound
playersInv.gameObject.SendMessage("PlayDropItemSound", SendMessageOptions.DontRequireReceiver);
//This will delete the item on use or remove 1 from the stack (if stackable).
if (deleteOnUse == true)
{
DeleteUsedItem();
}
}
//This takes care of deletion
function DeleteUsedItem()
{
if (item.stack == 1) //Remove item
{
playersInv.RemoveItem(this.gameObject.transform);
}
else //Remove from stack
{
item.stack -= 1;
}
Debug.Log(item.name + " has been deleted on use");
}
function addHealth() {
Vitals.health += 25;
}
function fireball() {
}
function lightningball() {
}
function iceball() {
}
function arcaneball() {
}
Thanks in advance!