Exemplo n.º 1
0
 private void OnEnable()
 {
     tar = (target as ZippyTerrain2D);
     Undo.undoRedoPerformed += UndoRedoPerformed;
     tar.Init();
     tar.CreateGround();
 }
Exemplo n.º 2
0
 void Update()
 {
     if (follow.position.x >= rightGround.cacheTransform.position.x)
     {
         // Left ground is no longer needed, it is will be replaced by the middle ground.
         // Change back to the original parent. (GroundContainer)
         leftGround.cacheTransform.parent = leftGround.parent;
         // Disable it so it doesn't show up if the player moves left.
         leftGround.gameObject.SetActive(false);
         // Rearrange terrains to the proper variables
         leftGround   = middleGround;
         middleGround = rightGround;
         // Get a random ground from the GroundContainer	to place at the right side.
         rightGround = GetRandomGround();
         // Positions the new right terrain piece next to the middle terrain.
         rightGround.transform.position = new Vector2(middleGround.cacheTransform.position.x + middleGround.width, transform.position.y);
     }
     else if (follow.position.x <= middleGround.cacheTransform.position.x)
     {
         // Pretty much the same as above.
         rightGround.cacheTransform.parent = rightGround.parent;
         rightGround.gameObject.SetActive(false);
         rightGround  = middleGround;
         middleGround = leftGround;
         leftGround   = GetRandomGround();
         leftGround.transform.position = new Vector2(middleGround.cacheTransform.position.x - middleGround.width, transform.position.y);
     }
     if (!parallaxScrolling)
     {
         return;
     }
     transform.position = new Vector2(follow.transform.position.x * xSpeed, follow.transform.position.y * ySpeed - yOffset);
 }
Exemplo n.º 3
0
    ZippyTerrain2D GetRandomGround()
    {
        ZippyTerrain2D r = groundContainer.GetChild(Random.Range(0, groundContainer.childCount)).GetComponent <ZippyTerrain2D>();;

        r.transform.parent = transform;
        r.gameObject.SetActive(true);
        return(r);
    }
Exemplo n.º 4
0
    ZippyTerrain2D GetRandomGround()
    {
        ZippyTerrain2D r = groundContainer.GetChild(Random.Range(0, groundContainer.childCount)).GetComponent <ZippyTerrain2D>();;

        r.transform.parent = transform;
        r.gameObject.SetActive(true);
        foreach (Transform child in r.transform)           //added so that the coins will respawn after being set to inactive from the rock picking them up
        {
            child.gameObject.SetActive(true);
        }
        return(r);
    }
    public void PositionOnTerrain()
    {
        if (!transform.parent)
        {
            return;
        }
        ZippyTerrain2D t = transform.parent.GetComponent <ZippyTerrain2D>();

        if (!t)
        {
            return;
        }
        float n = t.posY[FindClosestXpos(transform.position)];

        transform.localPosition = new Vector2(transform.localPosition.x, n + t.height + positionOffset);
    }
    int FindClosestXpos(Vector2 childPos)
    {
        ZippyTerrain2D t    = transform.parent.GetComponent <ZippyTerrain2D>();
        int            ind  = 0;
        float          prev = 10000000;

        for (int i = 0; i < t.posX.Length; i++)
        {
            Vector2 difference  = childPos - new Vector2(t.posX[i], t.posY[i]);
            var     distanceInX = Mathf.Abs(difference.x);
            //float dis = Vector2.Distance(childPos, new Vector2(t.posX[i], t.posY[i]));
            if (distanceInX < prev)
            {
                prev = distanceInX;
                ind  = i;
            }
        }
        return(ind);
    }
Exemplo n.º 7
0
 void Start()
 {
     GetParent();
     if (CheckForErrors())
     {
         this.enabled = false;
         return;
     }
     if (!startGround)
     {
         middleGround = GetRandomGround();
     }
     else
     {
         middleGround = startGround;
     }
     middleGround.transform.parent        = transform;
     middleGround.cacheTransform.position = transform.position;
     leftGround = GetRandomGround();
     leftGround.transform.position = new Vector2(middleGround.cacheTransform.position.x - leftGround.width, transform.position.y);
     rightGround = GetRandomGround();
     rightGround.transform.position = new Vector2(middleGround.cacheTransform.position.x + middleGround.width, transform.position.y);
     DisableAll();
 }