Пример #1
0
    protected virtual void AttachTarget(Targetable target, RaycastHit targettingInfo)
    {
        if (HasTarget())
        {
            ReleaseTarget();
        }

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

        var sourceTransform = GetTargettingSource();

        m_TargetDistance = (target.transform.position - sourceTransform.position).magnitude;
        m_TargetRotation = target.gameObject.transform.rotation;
        m_SourceRotation = sourceTransform.rotation;

        m_TargettingHandle = (GameObject)Instantiate(TargettingHandleTemplate);
        m_TargettingHandle.transform.position = target.transform.position;
        m_TargettingHandle.transform.rotation = target.transform.rotation;

        Rigidbody handleRB = m_TargettingHandle.GetComponent <Rigidbody>();

        if (null != handleRB && null != SourcePhysicsHandle)
        {
            SourcePhysicsHandle.connectedBody = handleRB;
        }

        target.AttachToTargettingSource(this);
    }