Created
May 26, 2016 07:55
-
-
Save peroon/88c9f318d405b8765d6109322e43b713 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEngine.UI; | |
| using System.Collections; | |
| using DG.Tweening; | |
| // Screen Space - Overrayで使える2Dパーティクル | |
| [RequireComponent (typeof (CanvasGroup))] | |
| public class CanvasParticle : MonoBehaviour { | |
| public int particleNum = 5; | |
| public GameObject prefab; | |
| // パーティクルサイズ | |
| public float minWidth = 10.0f; | |
| public float maxWidth = 20.0f; | |
| public float minRadius = 50.0f; | |
| public float maxRadius = 100.0f; | |
| public float fadeTime = 1.0f; | |
| void Start () { | |
| var rectTransform = this.GetComponent<RectTransform> (); | |
| for (int i = 0; i < particleNum; i++) { | |
| var go = Instantiate (prefab) as GameObject; | |
| var rect = go.GetComponent<RectTransform>(); | |
| // 親 | |
| rect.SetParent(this.transform); | |
| // 位置はこれ自身と同じ | |
| //rect.anchoredPosition = rectTransform.anchoredPosition; | |
| rect.anchoredPosition = Vector2.zero; | |
| // 色はランダム | |
| var image = go.GetComponent<Image>(); | |
| image.color = Color.HSVToRGB (Random.value, 1.0f, 1.0f); | |
| // 飛ぶ方向はランダム | |
| var rad = Mathf.PI * 2.0f * Random.value; | |
| var radius = Random.Range (minRadius, maxRadius); | |
| Vector2 targetPosition = rect.anchoredPosition + new Vector2 (radius * Mathf.Cos (rad), radius * Mathf.Sin (rad)); | |
| rect.DOAnchorPos (targetPosition, fadeTime).SetEase (Ease.Linear); | |
| // サイズ | |
| float size = Random.Range(minWidth, maxWidth); | |
| rect.sizeDelta = Vector2.one * size; | |
| } | |
| // フェードする | |
| this.GetComponent<CanvasGroup>().DOFade(0.0f, fadeTime); | |
| Destroy (this.gameObject, fadeTime + 1.0f); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment