Author Topic: Scroll View Question  (Read 5548 times)

Magic Frame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Scroll View Question
« on: October 22, 2013, 05:16:45 AM »
Hi,

I'm creating a Scroll View, I was wondering how to make each scroll bar graph view to present a different, alternating between one color and another color, leave a picture for better understanding.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Question
« Reply #1 on: October 22, 2013, 07:58:14 PM »
Since you're the one who's adding items to the scroll view, nothing is preventing you from having a background sprite on your entries and changing its color when you add new entries.

Magic Frame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Scroll View Question
« Reply #2 on: October 23, 2013, 03:33:04 AM »
If I get that, but as I can know when it comes one color or another?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Question
« Reply #3 on: October 23, 2013, 10:02:40 PM »
If (number of transform.childCount is even), use one color.
else, use another color.

Magic Frame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Scroll View Question
« Reply #4 on: November 15, 2013, 12:33:26 PM »
Hi Aren, thanks for reply, I'm trying and I can not get it to work, when I access the children have only the last note, do not tell me what the 1,2,3,4 .... any suggestions, leave the code

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BarGraphics : MonoBehaviour
  5. {
  6.         public int childNumber;
  7.         // Use this for initialization
  8.  
  9.         void Start ()
  10.        
  11.        
  12.         {
  13.        
  14.  
  15.  
  16.  
  17.         }
  18.        
  19.         // Update is called once per frame
  20.         void Update () {
  21.  
  22.  
  23.                 childNumber = GameObject.Find("Gridplayer").transform.childCount % 2;
  24.  
  25.  
  26.                 if ( childNumber ==0)
  27.                 {
  28.  
  29.                         //Is Odd!!!
  30.  
  31.  
  32.  
  33.                 }else
  34.                 {
  35.  
  36.  
  37.                         //Is Even!!!
  38.  
  39.  
  40.                 }
  41.  
  42.  
  43.  
  44.  
  45.        
  46.         }
  47. }



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Question
« Reply #5 on: November 15, 2013, 09:39:34 PM »
Never use GameObject.Find. It's very, very slow... and using it inside Update() -- which happens every frame -- is even worse.

Assuming this script of yours is attached to a row component, checking for the number of children in the update isn't the right place. You need to do it wherever you add the children. If you can't do it there, then do it once inside Start(). And instead of checking the total child count, you'd want to:
  1. for (int i = 0; i < transform.parent.childCount; ++i)
  2. {
  3.     if (transform.parent.GetChild(i) == transform)
  4.     {
  5.          // here you'd do (i % 2)
  6.         break;
  7.     }
  8. }