Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Dec 2015
    Posts
    1

    Modern UI Development in Unity: Board Layout Group Error, Video 4

    Hey guys,

    So I'm doing the UI tutorial, and I've ran into this bug when implementing the board layout group code that causes my buttons to overlap. Has anyone else ran into this? Additionally, I'm on Unity 5, if that makes any difference (I don't think it does in this case though).

    Code:
    	public void SetLayoutHorizontal () {
    
    		if (cellsPerRow <= 0) {
    			return;
    		}
    
    		var columnCount = Mathf.Ceil (rect.childCount / (float)cellsPerRow) - 1;
    
    		var currentRow = 0;
    		var currentColumn = 0;
    		var startX = -((float)cellsPerRow) * cellSize.x / 2f + (cellSize.x / 2);
    		var startY = -columnCount * cellSize.y / 2f;
    
    		for (var i = 0; i < rect.childCount; i++) {
    			var child = rect.GetChild (i) as RectTransform;
    			if (child == null) {
    				continue;
    			}
    
    			child.sizeDelta = cellSize;
    			child.anchoredPosition =
    				new Vector2 (startX + currentColumn * cellSize.x,
    				startY + currentRow * cellSize.y);
    
    			currentColumn++;
    
    			if (currentColumn % cellsPerRow == 0) {
    				currentColumn = 0;
    				currentRow++;
    			}
    		}
    
    		rect.sizeDelta
    		= new Vector2 (cellsPerRow * cellSize.x,
    			(columnCount + 1) * cellSize.y);
    	}
    I've attached a copy of the code from the tutorial via a screenshot, and my bug.

    Thanks ahead of time,
    Zach
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2016-01-04 at 3.07.53 PM.png 
Views:	88 
Size:	706.7 KB 
ID:	74590   Click image for larger version. 

Name:	Screen Shot 2016-01-04 at 3.06.13 PM.png 
Views:	74 
Size:	549.3 KB 
ID:	74591  

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •