graph.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class graph : MonoBehaviour { [SerializeField] Transform PointPrefab; [SerializeField,Range(10,100)] int resolution = 10; Transform[] points; // 初始化位置 private void Awake() { points=new Transform[resolution]; float step = 2f / resolution; var scale = Vector3.one * step; var position=Vector3.zero; for (int i=0; i < points.Length;i++) { Transform point = points[i] =Instantiate(PointPrefab); position.x = (i + 0.5f) * step - 1f; point.localPosition = position; point.localScale = scale; point.SetParent(transform,false); } } void Start() { } // Update is called once per frame void Update() { float time = Time.time; for (int i = 0; i < points.Length; i++) { Transform point = points[i]; Vector3 position = point.localPosition; position.y = Mathf.Sin(Mathf.PI * (position.x + time)); point.localPosition = position; } } }
标签:CatLikeCoding,point,int,Vector3,Transform,points,No.2,Basic,position From: https://www.cnblogs.com/lofu/p/17062152.html