Example #1
0
        private bool TryFixTo(D2dDestructible destructible)
        {
            var isDifferent = cachedDestructible != destructible;

            // Temporarily change parent
            transform.SetParent(destructible.transform, false);

            // Find world position of fixture if it were attached to tempDestructible
            var worldPosition = transform.TransformPoint(Offset);

            // Can fix to new point?
            if (destructible.SampleAlpha(worldPosition).a >= 128)
            {
                if (isDifferent == true)
                {
                    Unhook();

                    cachedDestructible = destructible;

                    Hook();
                }

                return(true);
            }

            // Change back to old parent
            transform.SetParent(cachedDestructible.transform, false);

            return(false);
        }
Example #2
0
        private void UpdateFixture()
        {
            if (cachedDestructible == null)
            {
                cachedDestructible = GetComponentInParent <D2dDestructible>();
            }

            if (cachedDestructible == null)
            {
                DestroyFixture();
            }
            else
            {
                var worldPosition = transform.TransformPoint(Offset);

                if (cachedDestructible.SampleAlpha(worldPosition).a < 128)
                {
                    DestroyFixture();
                }
            }
        }