首页 > 其他分享 >CatLikeCoding Basic No.2

CatLikeCoding Basic No.2

时间:2023-01-19 21:22:06浏览次数:43  
标签:CatLikeCoding point int Vector3 Transform points No.2 Basic position

 

 

 

 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

相关文章