- Home /
Brackeys Inventory System doubts...
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! :D
Answer by Owen Burk · Jan 04, 2014 at 03:13 PM
I'm not positive but instead of
Instantiate(fireparticle);
try (Whatever transform you want)
Instantiate (fireparticle, Vector3(0, 0, 0), Quaternion.identity);
Yes it works perfectly now; however, when I use the scroll, the fireball is launched at a random angle, which is not what I intend to do. I have an empty GameObject called SpellNode, from which I wish the fireball to fire from. The object is in front of the player, and I want the fireball to launch forwards. Can you help me? Thank you very much so far! :D
Use the position and rotation of the SpellNode object in the instantiate function.
Instantiate(fireparticle, spellNodeTransform.position, spellNodeTransform.rotation);
Assu$$anonymous$$g you have access to the spellNode's transform.
They are still co$$anonymous$$g out at random angles :/
Please, I would like assistance with this as soon as possible, I am working under a deadline and need this by the end of the day. Thank you all.
Answer by cwmanley · Jan 05, 2014 at 06:20 PM
Did you know there is a C# version on there website.
But that's not what I need. I already heavily modified this one, not going to start over again, thank you.
And the C# version does not work. When being exported there are loads of dependencies that were excluded.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Magic mouse scroll-wheel 1 Answer
how to make a texture scroll on an object? 2 Answers
Trouble Adjusting Stats (MP After Casting A Spell) 2 Answers
Scroll to change walk speed... 1 Answer