Quantcast
Viewing latest article 17
Browse Latest Browse All 41

variables within variables?

I have been writing some code, but it takes me a lot of time to write every single variable. I was hoping I could make it more efficient by using variables withing variables. Or at least, string or ints within variables to designate the variables that I want to alocate the value of. So, for example, I have: if (Input.GetKeyDown (KeyCode.Alpha2)) { key2 = false; obj2Type = 0; obj2CurAmmo = 0; obj2MaxAmmo = 0; obj2NextFire = 0; this.GetComponent ().DestroyAbilityImage (2); } if (Input.GetKeyDown (KeyCode.Alpha3)) { key3 = false; obj3Type = 0; obj3CurAmmo = 0; obj3MaxAmmo = 0; obj3NextFire = 0; this.GetComponent ().DestroyAbilityImage (3); } And I was hoping I could write something of the sort: if (Input.GetKeyDown (KeyCode.Alpha2)) { AssignVariable(2); } if (Input.GetKeyDown (KeyCode.Alpha3)) { AssignVariable(3); } AssignVariable(int it) { key[it] = false; obj[it]Type = 0; obj[it]CurAmmo = 0; obj[it]MaxAmmo = 0; obj[it]NextFire = 0; this.GetComponent ().DestroyAbilityImage ([it]); }

Viewing latest article 17
Browse Latest Browse All 41

Trending Articles