- Home /
This post has been wikified, any user with enough reputation can edit it.
List.add() not working when function called by 2nd script
<code>`public List units_selected = new List();
public void add_unit(Transform unit_to_add)
{
units_selected.Add(unit_to_add);
//units_selected.Insert(0,unit_to_add);
print (unit_to_add.transform.name);
//unu=unit_to_add;
}`</code>
is called when this happens :<code>
`if(selected){
renderer.material.color = Color.red;
if(select_debounce == false){ //cam.BroadcastMessage("add_unit",self,SendMessageOptions.DontRequireReceiver);
//print ("added");
cam.add_unit(self);
select_debounce = true;
}
}
`
From 2 days of debugging it appears that the function is called by my second script when I want it to (tested using print function) and also passes the right info, and the list editing itself works when called by the script its in. But for some reason when the function is called from the second script, it refuses to modify my list and gives me no debug errors to work on... The two scripts are the only ones in my entire scene and those references are the only time the list is mentioned.... Help ? edit: why does unity answers insist on obfuscating my code ?
Comment
Answer by RetepTrun · Jan 29, 2015 at 01:12 AM
Its because you assigned the_camera to a prefab, not the one in the scene :D