0

i have three same object with same script in scene, i also has one button for upgrade the object script's variable i selected

below is what i tried but still upgraded all of object variable instead just what i selected

what i want is when i selected one of the object on scene and clicked the button, then just selected object script variable upgraded instead all of the object script variable

public int lv;
public float hp;
public float damage;
public float atkSpeed;
public GameObject objBtnUpgrade;
public Button btnUpgrade;
void Start () {

    objBtnUpgrade = GameObject.Find ("BtnUpgrade");
    objBtnUpgrade.GetComponent<Button> ().onClick.AddListener(() => { UpgradeSummonLevel(); }); 

}
public void UpgradeSummonLevel(){
    lv = lv + 1;
    hp = hp + ((hp / 100) * 10);
    atkSpeed = atkSpeed + ((atkSpeed / 100) * 10);
    damage = damage + ((damage / 100) * 10);
}

1 Answer 1

1

Are you asking why every one of your objects is being upgraded?

But to answer you question as far as I understand, the most likely problem is that you have all of the objects that you are trying to influence called "BtnUpgrade". They should have differing names that way you can find a single one by its name.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, i solved it using this code void OnMouseDown(){ ButtonUpgradeElementScripts.selectedGameObject = gameObject; } when i click the object then the object will parse gameObject what i clicked to buttonScript. btw.. thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.