Пример #1
0
    public void Launch(Vector3 basicVelocity, Vector3 addForce)
    {
        this.transform.SetParent(null);

        m_Rigidbody.useGravity = false;

        m_Rigidbody.isKinematic = false;

        m_Rigidbody.velocity = basicVelocity;

        m_Rigidbody.AddForce(addForce);

        //生成导弹拖尾
        GameObject trailGameobject = trailEffectInfo.effectPool.SpawnGameObjectPoolItem(trailMountPoint.position, trailMountPoint.rotation);

        m_TrailHandler = trailGameobject.GetComponent <MissileTrail>();

        m_TrailHandler.Attach(trailMountPoint);

        m_AudioSource.enabled = true;

        m_Timer = Time.time;

        m_LastDetectPointPos = detectPoint.position - detectPoint.forward * detectExtendDistance;
    }
Пример #2
0
    void OnCollisionEnter(Collision collision)
    {
        for (int i = 0; i < collisionDetect_IgnoreLayers.Length; i++)
        {
            string layerName = collisionDetect_IgnoreLayers[i];

            int layer = LayerMask.NameToLayer(layerName);

            if (collision.transform.gameObject.layer == layer)
            {
                return;
            }
        }

        for (int i = 0; i < collisionDetect_IgnoreTags.Length; i++)
        {
            string tagName = collisionDetect_IgnoreTags[i];

            if (collision.transform.gameObject.CompareTag(tagName))
            {
                return;
            }
        }


        ContactPoint contectPoint = collision.contacts[0];

        for (int i = 0; i < hitExplosionDataArray.Length; i++)
        {
            int detectLayer = hitExplosionDataArray[i].effectItem.gameObject.layer;

            if (collision.transform.root.gameObject.layer == detectLayer)
            {
                m_MissileExplosionPoolDictionary[detectLayer].SpawnGameObjectPoolItem(contectPoint.point + contectPoint.normal * 0.05f, Quaternion.LookRotation(contectPoint.normal));

                break;
            }
        }

        GameObject hitRootGameObject = collision.transform.root.gameObject;

        LifeController lifeController = hitRootGameObject.GetComponent <LifeController>();

        if (lifeController != null)
        {
            lifeController.TakeDamage(damageTargetValue);
        }

        m_TrailHandler.Detach();

        m_TrailHandler = null;

        Recycle();
    }
Пример #3
0
    public void Update()
    {
        if (this.transform.parent != null)
        {
            return;
        }

        if (m_TargetBeLocked == false)
        {
            GameObject[] enemys = GameObject.FindGameObjectsWithTag("Enemy");

            for (int i = 0; i < enemys.Length; i++)
            {
                GameObject enemy = enemys[i];

                if (Vector3.Distance(enemy.transform.position, this.gameObject.transform.position) <= sightDistance &&
                    Vector3.Angle(enemy.transform.position - transform.position, transform.forward) <= sightViewAngle)
                {
                    m_AttackTarget = enemy;

                    m_TargetBeLocked = true;

                    break;
                }
            }
        }

        if (Time.time > m_Timer + autoDestroyTime)
        {
            spaceExplosionEffectInfo.effectPool.SpawnGameObjectPoolItem(this.transform.position, Quaternion.identity);

            m_TrailHandler.Detach();

            m_TrailHandler = null;

            Recycle();
        }
        else
        {
            PhysicsLineDetect();

            m_LastDetectPointPos = detectPoint.position - detectPoint.forward * detectExtendDistance;
        }
    }
Пример #4
0
    void OnEnable()
    {
        m_Rigidbody.useGravity = false;

        m_Rigidbody.isKinematic = true;

        m_Rigidbody.velocity = Vector3.zero;

        m_AttackTarget = null;

        m_TargetBeLocked = false;

        m_AudioSource.enabled = false;

        m_LastDetectPointPos = detectPoint.position - detectPoint.forward * detectExtendDistance;

        m_TrailHandler = null;

        m_Timer = 0.0f;
    }
Пример #5
0
    private void PhysicsLineDetect()
    {
        RaycastHit hitInfo;

        Vector3 currentDetectPoint = detectPoint.position;

#if UNITY_EDITOR
        // helper to visualise the ground check ray in the scene view
        Debug.DrawLine(m_LastDetectPointPos, currentDetectPoint, Color.red);
#endif

        if (Physics.Linecast(m_LastDetectPointPos, currentDetectPoint, out hitInfo, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore) == true)
        {
            for (int i = 0; i < collisionDetect_IgnoreLayers.Length; i++)
            {
                string layerName = collisionDetect_IgnoreLayers[i];

                int layer = LayerMask.NameToLayer(layerName);

                if (hitInfo.transform.gameObject.layer == layer)
                {
                    return;
                }
            }

            for (int i = 0; i < collisionDetect_IgnoreTags.Length; i++)
            {
                string tagName = collisionDetect_IgnoreTags[i];

                if (hitInfo.transform.gameObject.CompareTag(tagName))
                {
                    return;
                }
            }


            bool hasLayer = false;

            for (int i = 0; i < hitExplosionDataArray.Length; i++)
            {
                int detectLayer = hitExplosionDataArray[i].effectItem.gameObject.layer;

                if (hitInfo.transform.gameObject.layer == detectLayer)
                {
                    m_MissileExplosionPoolDictionary[detectLayer].SpawnGameObjectPoolItem(hitInfo.point + hitInfo.normal * 0.05f, Quaternion.LookRotation(hitInfo.normal));

                    hasLayer = true;

                    break;
                }
            }

            if (hasLayer == false)
            {
                spaceExplosionEffectInfo.effectPool.SpawnGameObjectPoolItem(hitInfo.point + hitInfo.normal * 0.05f, Quaternion.LookRotation(hitInfo.normal));
            }

            GameObject hitRootGameObject = hitInfo.transform.root.gameObject;

            LifeController lifeController = hitRootGameObject.GetComponent <LifeController>();

            if (lifeController != null)
            {
                lifeController.TakeDamage(damageTargetValue);
            }

            m_TrailHandler.Detach();

            m_TrailHandler = null;

            Recycle();
        }
    }