Done!
This commit is contained in:
41
Assets/Script/Graph.cs
Normal file
41
Assets/Script/Graph.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Graph : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
Transform pointPrefab = default;
|
||||
|
||||
[SerializeField, Range(10, 100)]
|
||||
int resolution = 10;
|
||||
|
||||
Transform[] points;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var step = 2.0f / resolution;
|
||||
var position = Vector3.zero;
|
||||
var scale = Vector3.one * step;
|
||||
points = new Transform[resolution];
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
Transform point = Instantiate(pointPrefab);
|
||||
position.x = (i + 0.5f) * step - 1.0f;
|
||||
point.localPosition = position;
|
||||
point.localScale = scale;
|
||||
point.SetParent(transform, false);
|
||||
points[i] = point;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Script/Graph.cs.meta
Normal file
11
Assets/Script/Graph.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14cd06bfa92d53e4ebc0cde4a0e39db8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user