Unity/おすすめアセット/紙吹雪
提供: 初心者エンジニアの簡易メモ
kayacの紙吹雪
- https://techblog.kayac.com/unity-physically-simulated-confetti にあるunitypackageを入れる
- prefab/Confettiをシーンに置く
- Confetti.csを空オブジェクトにAddComponentする
公式:https://techblog.kayac.com/unity-physically-simulated-confetti
5秒ごとに紙吹雪花火サンプル(Dotween必須)
void Confetti() { GameObject prefab = playRunView.confettiPrefab; GameObject confettiObject = Instantiate(prefab, Vector3.zero, Quaternion.identity); confettiObject.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); Vector3 initPosition = new Vector3(82, 5, 1); // Vector3 initPosition = new Vector3(0, 5, 1); confettiObject.GetComponent<Confetti>().PieceWidth = 3f; confettiObject.GetComponent<Confetti>().PieceLength = 3f; confettiObject.transform.localPosition = new Vector3(initPosition.x, 0, initPosition.z); var sequence = DOTween.Sequence(); sequence.Append(confettiObject.transform.DOLocalMoveY(initPosition.y, 0.5f)); sequence.Append(confettiObject.transform.DOLocalMoveY(initPosition.y * 0.8f, 5f)); sequence.Play().OnComplete(() => { confettiObject.GetComponent<Confetti>().EmitPiecePerSecond = 0; Destroy(confettiObject, 5f); Confetti(); }); }