public void Initialize() { spriteRenderer = GetComponent <SpriteRenderer> (); tailPiece = GetComponentInChildren <TailPiece> (); pieceWhenCollected = GetComponentInChildren <PieceWhenCollected> (); pieceWhenCollected.gameObject.SetActive(false); tailPiece.gameObject.SetActive(false); groundPiecesOnEast = GetGroundPiecesOnEast(); groundPiecesOnOvest = GetGroundPiecesOnOvest(); groundPiecesOnSouth = GetGroundPiecesOnSouth(); groundPiecesOnNorth = GetGroundPiecesOnNorth(); if (IsBoundPiece()) { spriteRenderer.sprite = spriteWhenIsBoundOfGround; spriteRenderer.enabled = true; } Destroy(boxCollider); try { groundPiecesAroundMe = GetGroundPiecesAroundMe(5); } catch { } }
public void Move() { switch (currDir) { case Direction.up: Y += Speed; break; case Direction.down: Y -= Speed; break; case Direction.left: X -= Speed; break; case Direction.right: X += Speed; break; } //Check self collision if (CheckCollideTail(X, Y)) { Die(); } TailPiece newTrail = new TailPiece(X, Y, tailTimer, new GameObject("tail", typeof(SpriteRenderer))); tail.Add(newTrail); newTrail.visual.GetComponent <Transform>().position = new Vector3(newTrail.Xpos, newTrail.Ypos, -40); newTrail.visual.GetComponent <SpriteRenderer>().sprite = tailColor; }
/// <summary> /// Process growing for update /// </summary> private void UpdateGrowing() { if(growCount > 0) { TailPiece tp = TailPiece.Create(this, tailPieces.Count > 0 ? tailPieces[tailPieces.Count - 1].GetComponent<GridTransform>() : gridTransform); tailPieces.Add(tp); growCount--; } }
/// <summary> /// Process growing for update /// </summary> private void UpdateGrowing() { if(growCount > 0) { TailPiece tp = TailPiece.Create(this, tailPieces.Count > 0 ? tailPieces[tailPieces.Count - 1].GetComponent<GridTransform>() : gridTransform); if(tailPieces.Count > 0) { TailPiece last = tailPieces.Last(); last.GetComponentInChildren<MeshRenderer>().material = bodyMat; } tp.GetComponentInChildren<MeshRenderer>().material = tailMat; tailPieces.Add(tp); growCount--; } }