Hello, I’m trying to make items/ upgrades for my in-game store. My store has two tiers of weapons: boosts and weapons. I’m trying to make a script that can teleport my player to a certain distances in my level (500 units of distance, 750 units of distance, and 1000 units of distance). My other tier (weapons) would all use the same script, but it would have a different value of hit points attached to it. I tried to make these scripts on my own, but nothing I made functioned properly. Anyone have any ideas on where to start?
Sounds like you have a multiple-step problem:
- Making/differentiating your weapons
- Shop interface (where you actually buy stuff)
- Retrieving bought weapons
For 1:
Have you tried storing your weapons as classes?
Example:
//C#, easily done in JS as well
public class Weapon{
string name = "firstWeapon";
int level = 1;
int cose = 500;
float range, damage;
bool doesCoolThing = true;
}
You can even extend it like so:
public class CoolerWeapon{
//does everything weapon does, but adds it's own stuff
int extraXPmultiplier = 5;
}
- Shop is easy. Try smt like:
public void BuyItem(Weapon w){
switch(w){//what's being bought
default: if(playersMoney > w.cost){
playersMoney -= w.cost;
PlayerPrefs.SetInt("has"+w.name, 1);//saves value for later
break;
}
}
}
3)…and then in your player/shooter script:
//JS, cause it's easy and I'm tired ;)
var hasWeapon1:boolean = false;
function Start(){
if( PlayerPrefs.GetInt("hasWeapon1") == 1){
hasWeapon1 = true;
}
}
...
if(hasWeapon1){
//Yay!
}
...
That’s a gross oversimplification, and of course that’s all just psuedo-code written in the dead of night (definitely not best practice; take it with a dash of salt), but that should at least give you some food for thought ![]()
BTW: This should probably be in the “Scripting” forum.
I already have a store gui, so I have that part down, but I don’t really understand what is going on in the first script, maybe it’s just because I’m used to JS though. I get scripts 2 and 3, where it’s monitoring the purchasing, and getting a weapon but I don’t really understand the first script. Could you describe it to me?