Beispiel #1
0
        void Awake()
        {
            animator = transform.parent.GetComponent <Animator>();
            Physics2D.IgnoreCollision(transform.GetComponent <EdgeCollider2D>(),
                                      transform.parent.Find("Fish").GetComponent <CapsuleCollider2D>());

            Physics2D.IgnoreCollision(transform.GetComponent <EdgeCollider2D>(),
                                      FindObjectOfType <Pankapu>().GetComponent <CapsuleCollider2D>());

            Physics2D.IgnoreCollision(transform.GetComponent <EdgeCollider2D>(),
                                      FindObjectOfType <An>().GetComponent <CapsuleCollider2D>());

            width   = PankapuConfig.ComputeRect(transform).x;
            height  = PankapuConfig.ComputeRect(transform).y;
            width  *= transform.parent.localScale.x;
            height *= transform.parent.localScale.y;

            leftTop  = transform.Find("AncherLeftTop");
            rightTop = transform.Find("AncherRightTop");

            leftTop.position  = new Vector3(transform.position.x - width / 2, transform.position.y + height / 2, transform.position.z);
            rightTop.position = new Vector3(transform.position.x + width / 2, transform.position.y + height / 2, transform.position.z);

            EventCenter.AddListener(EventType.AnRespawn, Reset);
        }
Beispiel #2
0
        /// <summary>
        /// Place the ice cube under water.
        /// </summary>
        public void PlaceIceCubeUnderWater()
        {
            Transform leftBottom       = underWaterBottom.Find("AncherLeftBottom");
            Transform rightBottom      = underWaterBottom.Find("AncherRightBottom");
            float     lengthOfCubeCell = PankapuConfig.ComputeRect(iceCubePool.transform).x;
            float     lengthOfIceCube  = Vector3.Distance(leftBottom.position, rightBottom.position) / 3;
            float     scaleX           = lengthOfIceCube / lengthOfCubeCell;

            iceCubePool.transform.localScale = new Vector3(scaleX, 0.5f, 1);

            // There are three segment to place the ice cube.
            if (transform.position.x > leftBottom.position.x && transform.position.x < leftBottom.position.x + lengthOfIceCube && leftIceCube == 1)
            {
                Vector3 iceCubeCenter = new Vector3(leftBottom.position.x + lengthOfIceCube / 2, ladderCheck.position.y, 0);
                LoadIceCube(iceCubePool, underWaterBottom, iceCubeCenter);
                leftIceCube--;
            }
            else if (transform.position.x > leftBottom.position.x + lengthOfIceCube && transform.position.x < leftBottom.position.x + 2 * lengthOfIceCube && middleIceCube == 1)
            {
                Vector3 iceCubeCenter = new Vector3(leftBottom.position.x + 3 * lengthOfIceCube / 2, ladderCheck.position.y, 0);
                LoadIceCube(iceCubePool, underWaterBottom, iceCubeCenter);
                middleIceCube--;
            }
            else if (transform.position.x > leftBottom.position.x + 2 * lengthOfIceCube && transform.position.x < rightBottom.position.x && rightIceCube == 1)
            {
                Vector3 iceCubeCenter = new Vector3(leftBottom.position.x + 5 * lengthOfIceCube / 2, ladderCheck.position.y, 0);
                LoadIceCube(iceCubePool, underWaterBottom, iceCubeCenter);
                rightIceCube--;
            }
            iceCubePool.transform.localScale = new Vector3(1, 1, 1);
        }
Beispiel #3
0
        void Awake()
        {
            hinge = GetComponent <HingeJoint2D>();
            left  = transform.Find("Left");
            right = transform.Find("Right");

            float width = PankapuConfig.ComputeRect(transform).x *transform.parent.localScale.x;

            left.position  = new Vector3(transform.position.x - width / 2 + offset, transform.position.y, transform.position.z);
            right.position = new Vector3(transform.position.x + width / 2 - offset, transform.position.y, transform.position.z);
        }
Beispiel #4
0
        // Start is called before the first frame update
        void Start()
        {
            left  = transform.Find("Left");
            right = transform.Find("Right");

            float width = PankapuConfig.ComputeRect(transform).x *transform.parent.localScale.x;

            left.position = new Vector3(transform.position.x - width / 2 + offset,
                                        transform.position.y, transform.position.z);
            right.position = new Vector3(transform.position.x + width / 2 - offset,
                                         transform.position.y, transform.position.z);
        }
Beispiel #5
0
        /// <summary>
        /// Place the ice block.
        /// </summary>
        public void PlaceIceBlock()
        {
            if (water.GetComponent <WaterFalls>() != null)
            {
                Transform leftBottom       = water.Find("AncherLeftTop");
                Transform rightBottom      = water.Find("AncherRightTop");
                float     lengthOfCubeCell = PankapuConfig.ComputeRect(iceCube.transform).x;
                float     lengthOfIceCube  = Vector3.Distance(leftBottom.position, rightBottom.position);
                float     scaleX           = lengthOfIceCube / lengthOfCubeCell - offsetOfScaleIceCube;
                iceCube.transform.localScale = new Vector3(scaleX, 0.5f, 1);

                Vector3 iceCubeCenter = new Vector3(leftBottom.position.x + lengthOfIceCube / 2, leftBottom.position.y, 0);
                LoadIceCube(iceCube, water, iceCubeCenter);
                iceCube.transform.localScale = new Vector3(1, 1, 1);
            }
            else
            {
                // compute size of ice cube
                float lengthOfIceCube = PankapuConfig.ComputeRect(iceCube.transform).x;

                // compute the ancher point of water bottom
                float width  = PankapuConfig.ComputeRect(water).x *water.parent.localScale.x;
                float height = PankapuConfig.ComputeRect(water).y *water.parent.localScale.y;

                Vector3 leftTop  = new Vector3(water.position.x - width / 2, water.position.y + height / 2, water.position.z);
                Vector3 rightTop = new Vector3(water.position.x + width / 2, water.position.y + height / 2, water.position.z);

                float lengthOfScaledIceCube = Vector3.Distance(leftTop, rightTop) / 2;
                float scaleX = lengthOfScaledIceCube / lengthOfIceCube;
                iceCube.transform.localScale = new Vector3(scaleX, 0.3f, 1);

                if (water.Find("IceCube(Clone)") == null)
                {
                    if (isFacingRight)
                    {
                        Vector3 iceCubeCenter = new Vector3(leftTop.x + (lengthOfScaledIceCube / 2) - offsetOfIceCubeTwo, rightTop.y, 0);
                        LoadIceCube(iceCube, water, iceCubeCenter);
                        placedIceCubePos = IceCubePosition.left;
                    }
                    else
                    {
                        Vector3 iceCubeCenter = new Vector3(rightTop.x - (lengthOfScaledIceCube / 2) + offsetOfIceCubeTwo, rightTop.y, 0);
                        LoadIceCube(iceCube, water, iceCubeCenter);
                        placedIceCubePos = IceCubePosition.right;
                    }
                }
                else
                {
                    if (placedIceCubePos == IceCubePosition.left)
                    {
                        float   xCenter       = rightTop.x - (lengthOfScaledIceCube / 2) + offsetOfIceCubeTwo;
                        Vector3 iceCubeCenter = new Vector3(xCenter, rightTop.y, 0);
                        LoadIceCube(iceCube, water, iceCubeCenter);
                        placedIceCubePos = IceCubePosition.right;
                    }
                    else if (placedIceCubePos == IceCubePosition.right)
                    {
                        float   xCenter       = leftTop.x + (lengthOfScaledIceCube / 2) - offsetOfIceCubeTwo;
                        Vector3 iceCubeCenter = new Vector3(xCenter, rightTop.y, 0);
                        LoadIceCube(iceCube, water, iceCubeCenter);
                        placedIceCubePos = IceCubePosition.left;
                    }
                }
                iceCube.transform.localScale = new Vector3(1, 1, 1);
            }
        }