コード例 #1
0
    //
    /// <summary>
    /// 发射子弹
    /// </summary>
    private void Shooting()
    {
        //transform.Translate(Vector3.right * Time.deltaTime * moveSpeed, Space.Self);
        //transform.position += transform.up * Time.deltaTime * moveSpeed;
        t += Time.deltaTime * moveSpeed;
        this.transform.position = Vector3.MoveTowards(startVector3, endVector3, t);

        if (Vector3.Distance(this.transform.position, startVector3) > maxDistance)
        {
            bulletPool.PutBack(this.gameObject);
        }
        else if (this.transform.position == endVector3)
        {
            //todo:回收子弹到资源池,声音特效,粒子特效,掉血功能销毁物体,受伤特效,弹痕特效
            bulletPool.PutBack(this.gameObject);

            //AudioSource.PlayClipAtPoint(DazhongClip, transform.localPosition);


            if (IsXueWuTexiao)
            {
                AudioPools.Instance.GetAudioSource(hit, transform.localPosition, 0.8f);
                texiao = Instantiate(_shouji);
                texiao.SetActive(true);
                texiao.transform.position = endVector3;
                texiao.AddComponent <DestroySelf>();
                texiao.GetComponent <DestroySelf>().Timer = 0.6f;
                IsXueWuTexiao = false;
            }
            else
            {
                //todo:播放火花特效
                AudioPools.Instance.GetAudioSource(DazhongClip, transform.localPosition, 0.7f);
                texiao = Instantiate(_huoHua);
                texiao.SetActive(true);
                texiao.transform.position = endVector3;
                texiao.AddComponent <DestroySelf>();
                texiao.GetComponent <DestroySelf>().Timer = 0.6f;
                IsXueWuTexiao = false;
            }

            if (HitGameObject != null)
            {
                Enemy aEnemy = HitGameObject.GetComponent <Enemy>();
                if (aEnemy != null)
                {
                    HitGameObject.GetComponent <Enemy>().Hp -= bulletPower;
                }
            }
        }
    }