示例#1
0
    public void ChangeTarget(CrystalBase newTarget)
    {
        if (target != null)
        {
            target.OnReleaseCrystal();
        }

        if (newTarget == null)
        {
            target = null;
            return;
        }

        target = newTarget;
        newTarget.OnTriggerCrystal();
    }
    private void FireBeam()
    {
        Debug.Log("fire");
        RaycastHit2D hit = Physics2D.Linecast(m_staffOrigin.position, m_mousePos, ~m_raycastIgnore.value);

        if (hit.transform != null)
        {
            Debug.DrawLine(m_staffOrigin.position, hit.point, Color.red);
        }
        else
        {
            Debug.DrawLine(m_staffOrigin.position, m_mousePos, Color.red);
        }

        if (hit.transform?.GetComponent <CrystalBase>() == null)
        {
            if (m_targetCrystal != null)
            {
                m_targetCrystal.OnReleaseCrystal();
            }

            m_targetCrystal = null;
            return;
        }

        if (m_targetCrystal != null && hit.transform == m_targetCrystal.transform)
        {
            return;
        }

        if (m_targetCrystal != null)
        {
            m_targetCrystal.OnReleaseCrystal();
        }

        m_targetCrystal = hit.transform.GetComponent <CrystalBase>();
        m_targetCrystal.OnTriggerCrystal();
    }