var steps_container = $("#steps")[0];
setTimeout(myFunction, 3000);
setInterval(frameUpdate, 50);
var n = 30;
var i=0;
var steps = [];
var steps_x = [];
for (i=0;i<n;i++)
{
var step = document.createElement("div");
step.id = "step";
var step_x = i * 24;
step.style.left = step_x.toString() + "px";
step.style.top = "10px";
steps[i] = step;
steps_x[i] = step_x;
steps_container.appendChild(step);
}
function frameUpdate()
{
setStepsPosition();
}
function setStepsPosition()
{
var i;
for (i=0;i<n;i++)
{
var step_x = steps_x[i];
step_x = step_x + 1;
var max_x = (n-1)*24;
if (step_x > max_x )
{
step_x = 0;
}
steps_x[i] = step_x;
steps[i].style.left = step_x.toString() + "px";
var r = 5;
var x_for_atan = step_x*r/max_x - (r/2);
// extra non linear
if (step_x<3*24)
{
x_for_atan = -(r/2) + 0.5;
}
if (step_x>=max_x - 3*24)
{
x_for_atan = +(r/2) - 0.5;
}
var y = 180 + 120 * Math.atan(x_for_atan);
steps[i].style.top = y.toString() + "px";
}
}
function myFunction() {
// alert('Hello');
}
// handle click and add class
button.on("click", function(){
banner.addClass("alt")
})
Taken from this jsfiddle:
The idea is to move objects one by one each one following the other one. In unity I have part of a code I did already but not sure how to convert and use this javascript jquery. My brother did this javascript jquery sample.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class MoveObjects : MonoBehaviour
{
public float speed = 3f;
private GameObject[] objectstoMove;
private List<GameObject> objectsMoving = new List<GameObject>();
// Use this for initialization
public void Init()
{
objectstoMove = GameObject.FindGameObjectsWithTag("Stair");
objectsMoving = new List<GameObject>(objectstoMove);
}
// Update is called once per frame
void Update()
{
if (objectstoMove != null)
{
float step = speed * Time.deltaTime;
for (int i = 0; i < objectstoMove.Length; i++)
{
objectsMoving[i].transform.Translate((objectsMoving[i].transform.up + objectsMoving[i].transform.forward) * step);
}
}
}
}
I can't figure out how to implement the javascript/jquery code with the unity/csharp code.
UPDATE: What I'm trying to is simulate stairs escalator. My first script create and position stairs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateStairs : MonoBehaviour
{
public GameObject stairsPrefab;
public float delay = 3;
public int stairsNumber = 5;
public Vector3 stairsStartPosition;
public Vector3 stairSize;
public Vector3 stairsSize;
public float stepWidthFactor = 1f;
public MoveObjects moveobjects;
private Vector3 stairsPosition;
private GameObject stairsParent;
// Use this for initialization
void Start()
{
stairsParent = GameObject.Find("Stairs");
StartCoroutine(BuildStairs());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator BuildStairs()
{
for (int i = 1; i <= stairsNumber; i++)
{
stairsPosition = new Vector3(
stairsStartPosition.x,
stairsStartPosition.y + (i * stairsSize.y),
stairsStartPosition.z + (i * stairsSize.y) * stepWidthFactor);
GameObject stairs = Instantiate(
stairsPrefab,
stairsPosition,
Quaternion.identity);
stairs.tag = "Stair";
stairs.transform.parent = stairsParent.transform;
stairs.transform.localScale = stairSize;
yield return new WaitForSeconds(delay);
}
moveobjects.Init();
}
}
Then I want to use the MoveObjects script to make the stairs escalator effect.

SetStepsPosition()and you can put the equivalent of that inUpdate.step.transform.position.x/y/zinstead of changingstep.style.left/top.