Пример #1
0
        private void Start()
        {
            PlatformRigidbody             = GetComponent <Rigidbody2D>();
            PlatformRigidbody.isKinematic = true;

            if (ObjectCatcher == null)
            {
                ObjectCatcher = GetComponent <ObjectCatcher>();
            }

            StartRelativeToParent = transform.localPosition;
            //Debug.LogError("local pos: " + transform.localPosition, this);

            // Allow to make platform only move when they became visible
            Renderer[] renderers = GetComponentsInChildren <Renderer>();
            for (int i = 0; i < renderers.Length; ++i)
            {
                var visibilityInformer = renderers[i].gameObject.AddComponent <VisibilityInformer>();
                visibilityInformer.objectBecameVisible = BecameVisible;
            }

            CalculateNodesWorldPositions();

            Initialize();
        }
Пример #2
0
        void Awake()
        {
            if (platformRigidbody == null)
            {
                platformRigidbody = GetComponent <Rigidbody2D>();
            }

            if (CatcherCollider == null)
            {
                CatcherCollider = GetComponent <Collider2D>();
            }


            ParentCatcher = null;
            Transform currentParent = transform.parent;

            while (currentParent != null)
            {
                ObjectCatcher parentCatcher = currentParent.GetComponent <ObjectCatcher>();

                if (parentCatcher != null)
                {
                    ParentCatcher = parentCatcher;
                }
                currentParent = currentParent.parent;
            }

            // if we have a parent platform catcher, we make it's move "bubble down" to that catcher, so any object caught by that platform catcher will also be moved by the parent catacher (e.g. a platform catacher on a pressure plate on top of a moving platform)
            if (ParentCatcher != null)
            {
                ParentCatcher.OnMovingDelegate += MoveCaughtObjects;
            }
        }