using System.Collections; using System.Collections.Generic; using UnityEngine; public class step : MonoBehaviour { public int Num = 20; public float Speed = 1f; public bool active = false; public GameObject pfab; public GameObject[] Steps; void Start() { Steps = new GameObject[Num]; for (int i = 0; i < Num; i++) { Steps[i] = Instantiate(pfab, new Vector3(Random.Range(-100, 100), Random.Range(-100, 100), Random.Range(-100, 100)), Quaternion.identity); Steps[i].transform.parent = transform; // 创建的对象父对象设置为当前对象 } } // Update is called once per frame void Update() { if(active) { float step = Speed * Time.deltaTime; for (int j = 0; j < Num; j++) { GameObject s = Steps[j]; s.transform.localPosition = new Vector3(Mathf.Lerp(s.transform.localPosition.x, 0, step), Mathf.Lerp(s.transform.localPosition.y, 0.1f + 0.3f * j, step), Mathf.Lerp(s.transform.localPosition.z, -1.1f * j, step));//插值算法 } } } }