#How to add a new value at the end of an array (like pushback in c++)
1 messages · Page 1 of 1 (latest)
void SpawnPoint()
{
var New = Instantiate(point,worldposition, Quaternion.identity, startingpoint);
lr.points.SetValue(New,lr.points.Length);
}
this is the code i have been using for spawning new points in my game
and lr.points is a transform[]
currently the set value isnt working
if anyone could help
yes i tried but it said that it doesn't exist
Because an array itself can not be extended. If you change it to a list, you can use the add function
uhh
how do i do that?
it wouldn't work
becouse when i do
one of my functions flip up
I mean, if you change the type of a variable, you'll have to change the type of the functions you pass that variables to as well.
So basically you have a few options
- change parameter of the method to the type of the variable
- change parameter of the method to a type the variable implements (don't do this if you don't understand inheritance and polymorphism)
- change variable to an array while passing using ToArray