Common script

Hey! I have a problem - I create script (Inventory), this script is included to axe and pickaxe. My problem is that axe and pickaxe “reads” the same values, so when pickaxe have a slot 2, axe have a slot 2 too. My english is a modest, but I think you understand my problem :wink:

Thanks in advance :wink:

This is a my script (variables and comments are in Polish):

  //miejsce slotów
private var slot : Rect = new Rect(-155, -245, 40, 30);
private var slot2 : Rect = new Rect(-100, -250, 40, 30);
  //inne
var mozna : boolean = false;
var Tekst : GUIText;
var wyl : boolean = false;
var tekstura : GUITexture;
  //sloty zajęte
private var slotz : boolean = false;
private var slotz2 : boolean = false;
private var slotz3 : boolean = false;
private var slotz4 : boolean = false;
private var slotz5 : boolean = false;
private var slotz6 : boolean = false;



  private function Update(){
  if(Input.GetMouseButtonDown(1)&&mozna==false&&BlokowanieInwentarz.inwentarz==true){
mozna=true;
BlokowanieInwentarz.mozna2=false;
Tekst.enabled=true;
}
  if(mozna==true&&Input.GetButtonDown("1")&&slotz==false){
tekstura.pixelInset = slot;
wyl=true;
slotz=true;
slotz2=false;
}
  if(mozna==true&&Input.GetButtonDown("2")&&slotz2==false){
slotz=false;
tekstura.pixelInset = slot2;
wyl=true;
slotz2=true;
}
  if(wyl){
Tekst.enabled=false;
BlokowanieInwentarz.mozna2=true;
mozna=false;
wyl=false;
}
}

I think your problem is having the Input logic in the class… It’s kinda difficult to read but from what I get, when you press the button “2”, the pixel inset of the texture you reference in your class will change to slot2. And to slot1 if you press the “1” button.

The fact that it does for the 2 objects is normal then.

If you want to do it but only for 1 of your object (the pickaxe for example), you have to either remove the Input logic from that class and add a kind of SetSlot() functionnality to that script so that when you press button “2” you only have the “selected” tool doing the SetSlot() function.

Here is some pseudo code:

selectedWeapon = "pickaxe";
if(Input.GetButtonDown("2"))
{
    selectedWeapon.SetSlot(2);
}

I hope this will help you a little and good luck!