- Home /
Question by
davidflynn2 · Aug 27, 2013 at 07:09 PM ·
c#arrayleveling
Array issue
I am trying to finish of my leveling scrip and each time you level it adds damage to your gun so you can do more damage. I have created an array of gameobjects to hold your guns but the problem is when you level its only adding it to one of the items in the array not all of them.
Here is my script:
public GameObject[] guns;
private Gun gunD;
void Start ()
{
gunD = gun.GetComponent<Gun>();
}
void Update ()
{
}
if(curLevel < lvl.Length && curExperience >= lvl[curLevel-1])//This check is our curent lvl is less then the max length if it is it checks if our experance is greater then cur lvls experince.
{
for (var i=0; i < guns.Length; i++)
{
gunD.Damage += gunDamage[curLevel-1];//Add the amount damage specified to the damage the gun does.
}
}
Comment
Best Answer
Answer by roojerry · Aug 27, 2013 at 07:12 PM
You are only adding damage to gunD in your for loop. Should be like this to loop through the guns:
for (var i=0; i < guns.Length; i++)
{
guns[i].Damage += gunDamage[curLevel-1];
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Loop through multidimensional array in C#(Unity) 1 Answer
Unity event calling function gets nullreferencexception on bool 0 Answers
Change sprite of image 1 Answer