简单使用对象池技术实现弹幕功能
UI界面
效果图
DanMuSystem.cs :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DanMuSystem : MonoBehaviour
{
public GameObject sendMsgText;
public Transform canvas;
public Transform objectPoolContent;
public Button sendButton;
public Button deleteButton;
public InputField inputField;
List<GameObject> msgTextList = new List<GameObject>();
//对象池
public List<GameObject> objectPool = new List<GameObject>();
//对象池个数
public int objcetCount;
float scrrenWeight = 0;//宽
float screenHeight = 0;//高
float fixheight = 0; //每块的高度
float fixwidth = 0; //每块的宽度
int wCount = 30; //宽的块数
int hCount = 20; //高的块数
int rdText = 0; //文字个数
// Start is called before the first frame update
void Start()
{
screenHeight = Screen.height;
scrrenWeight = Screen.width;
fixheight = screenHeight / hCount;
fixwidth = scrrenWeight / wCount;
sendButton.onClick.AddListener<