escalator

Hi everyone!

I need some help. I have an escalator, which have 45 stair steps. Each one of them moving exactly the same way. But there sould be an 8 frame time shift due to proper seen… In other words, ie, 2nd step must start it’s loop 8 frames before the 1st one, and so the rest…

I tried to duplicate *.anim files up to 45 and make this shift indiviually for each one of them, it works for 5-6 steps, but when I came up to 20’s, program chrashed :slight_smile:

I think there should be a way to do that. via scripting or so…

Is there anyone who could help me please…
Regards.

Welcome to the forums!

There is definitely a way to do it with scripts. If you can show the script that crashes Unity, it’s a little easier to help.

Well actually ! don’t use any script. I am just applying anim file to objects.

And as I mentioned, I modify the anim files…

I know nothing about scripting. Only way for me, is to try already written ones and may be (if I am lucky) some basic modifications on them… But! I learn quickly :slight_smile:

If you could advise some documents or links, I will try…

Thanks…

One possibility is to use just one animation. Each step can use that one. Certainly you need to specify which step starts with which frame of the animation. The following script is not tested. Place it in each step. If the escalator has 10 steps, you need to enter 10 in each component for the step count. It is safer to start the step number at 0 and go up to 9 or whatever the number of steps is.

using UnityEngine;
using System.Collections;

public class EscalatorStep : MonoBehaviour {

	public int stepNumber;
	public int stepCount;
	
	private void Start () {
		Animation animation = GetComponent <Animation> ();
		if (animation == null) {
			Debug.Log ("The Escalator Step script must be placed in a game object that has an animation component!");
			return;
		}
		animation.Play ();
		foreach (AnimationState animationState in animation) {
			animationState.time = (float) stepNumber * animationState.length / (float) stepCount;
		}
	}
}

Dear Dantus,
// or who may answer…

I thank you for your time spend… I try to apply the script you give, I increase both step number and count but there is still only one cube rotating…
Did I do something wrong?

And here is big pictiure more detailed

Thanks.

You need one cube per step. I can only see one cube.

YES! YES! YESSSSSSSS!
:slight_smile:
Thank you extremely so much :slight_smile:

It is even carrying my player to 2nd floor :slight_smile:

:slight_smile: