54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using ZXK.Framework;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 对象池管理_测试
|
|
*******************************************************************************/
|
|
namespace ZXK.Test
|
|
{
|
|
public class GunObject : MonoBehaviour
|
|
{
|
|
Transform firepoint;
|
|
Transform FirePoint
|
|
{
|
|
get
|
|
{
|
|
if (firepoint == null)
|
|
firepoint = transform.Find("FirePoint");
|
|
return firepoint;
|
|
}
|
|
}
|
|
|
|
//子弹的预制体
|
|
GameObject bulletPrefab;
|
|
|
|
//射击的力度
|
|
public float shotForece = 1000;
|
|
|
|
void Awake()
|
|
{
|
|
bulletPrefab = Resources.Load<GameObject>("PoolMngPrefab/Bullet");
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
//生成子弹
|
|
//GameObject go = Instantiate(bulletPrefab, FirePoint.position, Quaternion.identity);
|
|
GameObject go = ObjectPoolsManager.Instance.Spawn(bulletPrefab, FirePoint.position, Quaternion.identity);
|
|
|
|
//发射子弹
|
|
go.GetComponent<Rigidbody>().AddForce(Vector3.forward * shotForece);
|
|
|
|
//5秒后销毁子弹
|
|
//Destroy(go, 5);
|
|
ObjectPoolsManager.Instance.Despawn(go, 5);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|