- Home /
The question is answered, right answer was accepted
Making A Universal Pickup Script
Hello Everyone, Right now i am working on a game that has 100 weapons/items that can be picked up my question is if there is a way to assign a variable in the inspector (like savescript.weapon1 = 1) but have is so that i can change what variable is being changed without making 100 different scripts, if anyone has an answer or know where i can find one that would be greatly appreciated! Thanks, -Tom
So you have a variable that tells the game which of your items you have right?
Answer by ExplodingCookie · Jun 16, 2014 at 05:00 PM
I think I know what you're trying to do here. Attach this script to the pickup item.
var itemCode = 1; //This tells us which item this pickup is
var saveState : //Replace this comment with the name of the save state script
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Player") { //This lets us see that the collider we hit is the player
saveState.weapon1 = itemCode; //Sets the save state to this weapon we picked up
GameObject.Destroy(gameObject); //Gets rid of the pickup
}
}
This script is in JavaScript. Which means that You'll have to do some modifications if get it to work with a C# Save State
~ExplodingCookie
Don't forget to label that answer as accepted so other people know you have been helped.
Follow this Question
Related Questions
Java for android script help??? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How would go about making a weapon pick up? 3 Answers
make inventory script get variables from item's script 0 Answers
Values lost? 1 Answer