LoginSignup
2
3

More than 5 years have passed since last update.

Unityでパーティクルからイーサンくんを生成してみる

Posted at

ba802623f0ab1def1f7232c57350f416.gif

こんなん

three.jsでできたんでUnityでもできるだろ〜なと思ってたらできました。

なおFPSは10で、実用性がない模様。

shaderに頂点データ送る必要ある。

コード

qiita.csharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MakingMeshParticle : MonoBehaviour {

    [SerializeField]
    private GameObject cube,character;

    List<GameObject> cubes = new List<GameObject>();
    List<Vector3> cubesTransform = new List<Vector3>();

    Mesh mesh{set {this.mesh= value;} get{return character.GetComponent <SkinnedMeshRenderer> ().sharedMesh;}}

    // Use this for initialization

    Vector3[] normals ;
    void Start () {

        Vector3[] vertices = mesh.vertices;
        normals = mesh.normals;


        mesh.vertices = vertices;

        for(int i =0;i<vertices.Length; i++){
            cubes.Add((GameObject)Instantiate (cube, vertices[i], Quaternion.identity));
            cubes [i].GetComponent<Renderer> ().material.color = Color.black;
            cubesTransform.Add (vertices [i]);
        }

    }

    // Update is called once per frame

    float n =0;
    void Update () {

        for(int i =1;i<cubes.Count; i++){
            cubes [i].transform.position = Vector3.Lerp(cubesTransform[i] ,new Vector3(Vector3.Magnitude(cubesTransform[i])*Mathf.Sin(i*100+Time.time),0,Mathf.Cos(i*100+Time.time)) ,Mathf.Sin(Time.time));
        }
    }
}

頂点のデータ配列を用意して、その値をgameobjectの位置情報に入れ込む。

僕のMacbookAirでもいい感じで動かしたいから、computeShader使えないからどうしたもんか。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3