csharp UI效果2D
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp UI效果2D相关的知识,希望对你有一定的参考价值。
using UnityEngine;
using UnityEngine.UI;
public class UIEffect : MonoBehaviour {
[SerializeField] private RectTransform targetRect;
[SerializeField] private ParticleSystem particle;
private Canvas _canvas;
public Canvas Canvas { get { return this._canvas ? this._canvas : this._canvas = targetRect.GetComponent<Graphic> ().canvas; } }
// Start is called before the first frame update
void Start () {
//RectTransformをスクリーン座標に変換
Vector2 screenPos = RectTransformUtility.WorldToScreenPoint (Canvas.worldCamera, targetRect.position);
//ワールド座標
Vector3 worldPos = Vector3.zero;
//スクリーン座標→ワールド座標に変換
RectTransformUtility.ScreenPointToWorldPointInRectangle (targetRect, screenPos, Canvas.worldCamera, out worldPos);
worldPos.z = 0.0f;
particle.transform.position = worldPos;
particle.Emit (1);
}
}
以上是关于csharp UI效果2D的主要内容,如果未能解决你的问题,请参考以下文章