예제 #1
0
    //public static BulletManager Instance;

    //void Awake()
    //{
    //    Instance = this;
    //}

    /// <summary>
    /// 发射子弹
    /// </summary>
    /// <param name="bulletModel"></param>
    /// <param name="pool"></param>
    public void DoShoot(BulletModel bulletModel, BasePool pool)
    {
        int num = bulletModel.Count / 2;

        for (int i = 0; i < bulletModel.Count; i++)
        {
            GameObject go         = pool.Get(bulletModel.InitPosition, bulletModel.LifeTime); //从对象池中获取 // 初始位置即enemy当前位置
            BulletMove bulletMove = go.GetComponent <BulletMove>();
            var        render     = go.GetComponent <MeshRenderer>();
            if (render != null)
            {
                go.GetComponent <MeshRenderer>().material?.SetColor("_EmissionColor", bulletModel.Color);
            }
            bulletMove.BulletSpeed = bulletModel.Speed;
            bulletMove.DelayTime   = bulletModel.DelayTime;

            if (bulletModel.Count % 2 == 1)
            {
                go.transform.rotation = bulletModel.Direction * Quaternion.Euler(0, 0, -(bulletModel.Angle * num)); // 绕Z轴旋转 , 要带负号
                go.transform.position = go.transform.position + go.transform.right * num * bulletModel.Distance;
                num--;
            }
            else
            {
                go.transform.rotation = bulletModel.Direction * Quaternion.Euler(0, 0, -(bulletModel.Angle / 2 + bulletModel.Angle * (num - 1)));  // 绕Z轴旋转
                go.transform.position = go.transform.position + go.transform.right * ((num - 1) * bulletModel.Distance + bulletModel.Distance / 2);
                num--;
            }
            go.transform.position = go.transform.position + go.transform.forward * bulletModel.ShiftInitPos;
        }
    }
예제 #2
0
    /// <summary>
    ///
    /// </summary>
    public void Init()
    {
        GameObject enemy = Resources.Load <GameObject>("Prefabs/Enemy");

        pool = GameObjectPoolManager.Instance.CreatGameObjectPool <BasePool>("Prefabs/Enemy", enemy);

        enemy = pool.Get(new Vector3(10, 20, 0), 0); //
        pool.Remove(enemy);
        //YaoJing1 yaoJing = enemy.GetComponent<YaoJing1>();
        //yaoJing.MoveEndPoint = new Vector3(-10, -10, 0);
        //yaoJing.MoveSpeed = 0.5f;
        //yaoJing.FireCD = 0.5f;
    }
예제 #3
0
    void FixedUpdate()
    {
        _timer += Time.fixedDeltaTime;
        if (_timer >= 0.2 && enemyCount <= 20)
        {
            GameObject go      = pool.Get(new Vector3(10, 20, 0), 0); //
            YaoJing1   yaoJing = go.GetComponent <YaoJing1>();
            yaoJing.MoveEndPoint = new Vector3(-20, 0, 0);
            yaoJing.MoveSpeed    = 0.5f;
            yaoJing.FireCD       = 0.1f;

            _timer = 0;
            enemyCount++;
        }
    }