Problem initializing an object inside a loop in c#.

Hi,
I am facing a problem with initializing Animation objects inside a loop in C#. The code is as follows. BasicAnim is a custom Animation object. For one animation, which works :

    _appearAnimations[0] = new BasicAnim<Vector3>();
	_appearAnimations[0].duration = duration;
	word = word_list[1];
	_appearAnimations[0].AddTarget(val => word.transform.position = val);
	_appearAnimations[0].easingFunc = AUBasicAnim.EaseNone;
	_appearAnimations[0].fromValue = p1_list[1];
	_appearAnimations[0].toValue   = p2_list[1];
	_appearAnimations[0].AddListener(this);

But when i loop them, it does nt work.

	for (int i = 0; i < word_list.Count; i++)
	{
		_appearAnimations *= new BasicAnim();*

appearAnimations*.duration = duration;
word = word_list;
_appearAnimations.AddTarget(val => word.transform.position = val);
_appearAnimations.easingFunc = AUBasicAnim.EaseNone;
_appearAnimations.fromValue = p1_list;
_appearAnimations.toValue = p2_list;
_appearAnimations.AddListener(this);*

* }*
I call the _appearAnimations.play in a loop later and only the last animation plays. I am new with C# so am unsure what could go wrong here. Any help is appreciated.
Thanks,
O_

1 Answer

1

The biggest difference I can see between the 2 examples of working/not working you have here is between the following lines:

working - ‘word = word_list[1];’ not working - ‘word = word_list*;’*
_appearAnimations[0].fromValue = p1_list[1];
_appearAnimations[0].toValue = p2_list[1];
appearAnimations.fromValue = p1_list*;
_appearAnimations.toValue = p2_list;*

seems like you might need to change the i value in the not working code snippet to potentially [i + 1] or whatever you need to for those objects._