以下がオブジェクトにアタッチするスクリプトです。
開始と同時に点となって散らばってるんですが、
Invoke()関数を使って10秒後に戻そうと思ってるのですが、
散らばったままで動きません。どこが間違ってるのでしょう。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PointBack : MonoBehaviour { MeshFilter MF; Vector3[] PreVertices; Mesh mesh; public float speed = 0.15f; public bool ok = false; public Vector3[] ver; //初期の頂点情報を記録 void Awake(){ mesh = GetComponent<MeshFilter> ().mesh; PreVertices = mesh.vertices; } void Start () { //頂点を表示 MF = GetComponent<MeshFilter>(); MF.mesh.SetIndices(MF.mesh.GetIndices(0),MeshTopology.Points,0); //開始時点で頂点を散らす Vector3[] ver = mesh.vertices; for (int i = 0; i < ver.Length; i++) { ver [i].x += speed * Random.Range (-50f, 50f) * Time.deltaTime; ver [i].y += speed * Random.Range (-50f, 50f) * Time.deltaTime; ver [i].z += speed * Random.Range (-50f, 50f) * Time.deltaTime; } mesh.vertices = ver; //〇秒後に元の時計の形に戻す Invoke("PreDisplay", 10f); } float smoothTime = 0.5f; Vector3 velocity = Vector3.zero; // Update is called once per frame void Update () { if (ok) { //ターゲットは元の位置 Vector3[] target = PreVertices; ///Vector3[] ver2 = mesh.vertices; for (int i = 0; i < target.Length; i++) { ver[i] = Vector3.SmoothDamp (transform.position, target [i], ref velocity, smoothTime); } mesh.vertices = ver; mesh.RecalculateBounds (); } } void PreDisplay(){ ok = true; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/18 05:23