Search Unity

Reaching a Script of GameObject List?

Discussion in 'Scripting' started by Sphynxinator, Aug 29, 2012.

  1. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Hello. I want to ask some questions about gameObject List. I have a gameObject list, and I want to reach its attached script and call a function from it. Can we use the code like this?

    GO_Harf goh0 = (GO_Harf)ananList.GetComponent("GO_Harf");

    GO_Harf is the name of script that attached to a game object that from the List that named ananList. "i" is zero. Thus it should reach the script of the gameObject that is in the list but it doesn't work. Why?

    Basically, I'm asking this: "How can I reach to a script of a Game Object that is in Game Object List?"

    Sorry for bad description.

    Thanks.
     
    Last edited: Aug 29, 2012
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I personally prefer to use the generic get component method, but your does not look wrong.
    Code (csharp):
    1. GO_Harf goh0 = ananList[i].GetComponent<GO_Harf>();
    If after that call goh0 is null, the game object simply has no GO_Harf component in it. If it is in a child of that game object, you may use GetComponentInChildren. Check the list with the game objects and see if the component really exists.
     
  3. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    I checked now and it exists. Otherwise, it should give "NullException" error maybe?
     
  4. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    If the game object has not been found and you try to execute something in that component then it will return null exception, yes. It's good practice to do null checks though.
     
    Last edited: Aug 29, 2012
  5. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    But, it doesn't give NullException error. :( it doesn't give any errors.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What cjow said correctly is that if you perform any call on the found component, like
    Code (csharp):
    1. Debug.Log (goh0.name);
    you are going to get a null reference exception. If that doesn't happen, the component was found!
     
  7. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Oh, but I don't get an error. I also tried Debug.Log(goh0.name); and it returned as "HarfPrefab(Clone)". Then there is no error in that line. Maybe I can give the project file? I was trying to make a vector font that prints on the screen with typewriter effect. Typewriter effect makes confusion but I want to program it. All professional games uses typewriter effect I think and I like it too.

    Whatever, maybe it was about the function that I want to call. Its name is "YaratmaFonk" and it is in the gameObject's script(GO_Harf) that I want to reach. I made something like this:

    ananList.Add(Instantiate(anan, Vector3.zero, Quaternion.identity) as GameObject);
    GO_Harf goh0 = (GO_Harf)ananList.GetComponent("GO_Harf");
    goh0.YaratmaFonk(offsetX, offsetY, 0);

    Maybe there was something wrong with other part of the code? I give the project if anyone wants to look at it.

    Thanks again.

    View attachment $Deneme.rar
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Had a look at your project, but unfortunately I don't understand your code due to the language. I see some kind of type writer effect, but I have no idea what you would like to achieve. Please explain what is going wrong and what should actually happen. Otherwise it's about impossible for us to help.
     
  9. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Oh what do you mean by "language"? Because of the C# or I wrote confusing code? :( Oh I get it, I wrote the language in my native language. Sorry about that. Thanks for you effort by the way. I will explain what is going on.

    I was trying to print vector font to the screen using GUI. I made all the letters and then I made a gameObject. There are two scripts on the project. "YaziKodu" is sending some information to GO_Harf script. GO_Harf script is attached to a letter prefab. YaziKodu makes the letter prefab appear on the screen with Instantiate, then I call a function from GO_Harf in YaziKodu and send the information of letter's position and code(for example code of letter A is 0 because it is first letter). Also if "\n" character used or nax letter on a line is 25, yOffset increased by one and xOffset set zero. There are some time code that makes print the letter in time.

    Whatever, my description is confusing I think. I will say what's going on simple. For example, I want to print "Hello!" to the screen. The size of the letters are for example 20x20. I will instantiate six characters but when I instantiate the first character, its xOffset increased by one. GUI takes the offset data and multiples the offset data with size of the letter. First it will print to the x=0 the letter(xOffset is 0, size is 20, 0x20=0). Then xOffset is increased by one. Then now it will be 1x20, and it will print to the x=20. It goes like x=40, x=60 until sixth character. There are a function that sets the position and code of the letter that going to be printed. I reach to function and send to the datas of the letters.

    Here's the meaning of words:
    yazi: text
    satir: line
    harf: letter
    islem: operation
    zaman: time
    sayac: counter
    anan: it has a meaning but it is random, just a word, I don't want to say its meaning :D.
    harfDegiskeni: letter variable
    also yaziKodu means letter code.

    Sorry for confusing text, I wrote it fast as I can.
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Let's face it, if we knew it, you would be banned from the forum ;) !

    I'll see what I can do.
     
  11. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am pretty sure you would have found the error on your own, if you had made the code structure a little more readable. You have those huge switch code blocks. If you think they are really needed, I would propose you to move them into a separate method. Like that it becomes a lot easier to see what is going on.

    The error happens in YaziKodu:
    Code (csharp):
    1. if(satirIslem == 0){
    2.     offsetX=0;
    3.     offsetY++;
    4. }
    The inner part of the code block is always executed. You can try it out. Just place some Debug.Log (Time.realtimeSinceStartup); in there. As a consequence, offsetX is always reset to zero.
     
  12. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    I don't want to get banned from the forum. :D Actually it wasn't bad. It just means "your momma". :D I wrote it like that because I was bored. :D

    It works now. Instead of this:

    if(satirIslem == 0){
    offsetX=0;
    offsetY++;
    }

    I wrote this:

    if(offsetX < 24){
    offsetX=0;
    offsetY++;
    }

    Actually it didn't work again but I found some mistakes in the code and fixed them as you said, I found other mistakes on my own. Then it worked. By the way, It was not readable because I was thinking like "OK, I should make the code first, I will make it readable after writing a working code". Looks like I was wrong a bit. I accept I am a newbie coder, I can't take education about programming, I wish I could. I am open to your suggestions, :p I don't like this huge switch block too. I can't believe I made a stupid module operation, looks like my math is bad. I learnt that if the code don't work as you want and it don't give errors, maybe you can check up other parts. :) Whatever, it works, you helped me so much, thanks for your effort! Thanks to cjow too. Here is a caps:

    http://imgim.com/print.jpg

    By the way, can you see the huge amount of gameObject in the Hierarchy panel? It looks so bad. Suddenly I found a solution, but I don't think it would help after I thinking on it a while. It was about adding the letter to other variable(for example I want to print "hello!" then I give the letters to another string variable in time and then I print it that variable with GUI but new lines won't work, maybe I can print lines as seperate strings.)I need a solution about fixing that big amount of gameObject and seperated letter graphics now. :(
     
    Last edited: Aug 30, 2012
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am glad it was useful!

    Unfortunately I don't have the time to help you with the other problem.
     
  14. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Oh OK then, forget about it. Actually in that case, you helped me really much although you don't have time. Thanks. I should find out myself.
     
  15. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Couldn't resist.

    At the moment each character is an object of type GO_Harf. I would try to keep that class, but make sure it doesn't inherit MonoBehaviour and there will certainly be no more Instantiate call, so you would need to create instances with new. Instead there should be another class that manages the rendering and knows all the character textures. That manager inherits MonoBehaviour. It certainly needs a list with all the characters (List of Harf).

    Not sure if that is useful for you.
     
  16. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    I don't get it the suppose of this way. Why we use Class without MonoBehaviour instead of Instantiate and a Class that inherits MonoBehaviour? I thought of a new way that reduce Instantiated object number to 1, 2 or 3. I tried to describe it here but it is too long. But if you want, I can code it and give the project file here. You can give me some advices to reduce the big switch code blocks also. :D
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can also just post the scripts. Like that, others may have a look at it too. But that's up to you.
     
  18. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Oh I'm trying to write the code since 3-4 hours, it gets boring I can't take it anymore I've quitted writing. :D Maybe if I continue to writing the code, I will success but I don't want to write it over and over, sorry. And I hate that huge switch block. I find ideas, I mean maybe I can do bitmap fonts with just one script but I can't write it because I get tired and confused quickly.

    Here's the unfinished code. It doesn't give error but it doesn't print fonts either. And this is the simplest form. It was splitted into two scripts once.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class TextController : MonoBehaviour {
    7.     public Texture2D[] theFont;
    8.  
    9.     private string text1before;
    10.     private string text1after;
    11.     private int arrayCounter;
    12.     private int offset;
    13.     private float timeCounter;
    14.     private int guiCounter;
    15.  
    16.     void Start() {
    17.         text1before = "HOW ARE YOU?";
    18.         text1after = null;
    19.         arrayCounter = 0;
    20.         timeCounter = 0;
    21.         guiCounter = 0;
    22.         offset = 0;
    23.     }
    24.  
    25.     void Update() {
    26.         timeCounter += Time.deltaTime;
    27.  
    28.         if(timeCounter >= 0.1) {
    29.             if(arrayCounter < text1before.Length){
    30.                 switch(text1before[arrayCounter]){
    31.                     case 'A':
    32.                         text1after = text1after + 'A';
    33.                         break;
    34.                     case 'B':
    35.                         text1after = text1after + 'B';
    36.                         break;
    37.                     case 'C':
    38.                         text1after = text1after + 'C';
    39.                         break;
    40.                     case '\u00C7':
    41.                         text1after = text1after + '\u00C7';
    42.                         break;
    43.                     case 'D':
    44.                         text1after = text1after + 'D';
    45.                         break;
    46.                     case 'E':
    47.                         text1after = text1after + 'E';
    48.                         break;
    49.                     case 'F':
    50.                         text1after = text1after + 'F';
    51.                         break;
    52.                     case 'G':
    53.                         text1after = text1after + 'G';
    54.                         break;
    55.                     case '\u011E':
    56.                         text1after = text1after + '\u011E';
    57.                         break;
    58.                     case 'H':
    59.                         text1after = text1after + 'H';
    60.                         break;
    61.                     case 'I':
    62.                         text1after = text1after + 'I';
    63.                         break;
    64.                     case '\u0130':
    65.                         text1after = text1after + '\u0130';
    66.                         break;
    67.                     case 'J':
    68.                         text1after = text1after + 'J';
    69.                         break;
    70.                     case 'K':
    71.                         text1after = text1after + 'K';
    72.                         break;
    73.                     case 'L':
    74.                         text1after = text1after + 'L';
    75.                         break;
    76.                     case 'M':
    77.                         text1after = text1after + 'M';
    78.                         break;
    79.                     case 'N':
    80.                         text1after = text1after + 'N';
    81.                         break;
    82.                     case 'O':
    83.                         text1after = text1after + 'O';
    84.                         break;
    85.                     case '\u00D6':
    86.                         text1after = text1after + '\u00D6';
    87.                         break;
    88.                     case 'P':
    89.                         text1after = text1after + 'P';
    90.                         break;
    91.                     case 'Q':
    92.                         text1after = text1after + 'Q';
    93.                         break;
    94.                     case 'R':
    95.                         text1after = text1after + 'R';
    96.                         break;
    97.                     case 'S':
    98.                         text1after = text1after + 'S';
    99.                         break;
    100.                     case '\u015E':
    101.                         text1after = text1after + '\u015E';
    102.                         break;
    103.                     case 'T':
    104.                         text1after = text1after + 'T';
    105.                         break;
    106.                     case 'U':
    107.                         text1after = text1after + 'U';
    108.                         break;
    109.                     case '\u00DC':
    110.                         text1after = text1after + '\u00DC';
    111.                         break;
    112.                     case 'V':
    113.                         text1after = text1after + 'V';
    114.                         break;
    115.                     case 'W':
    116.                         text1after = text1after + 'W';
    117.                         break;
    118.                     case 'X':
    119.                         text1after = text1after + 'X';
    120.                         break;
    121.                     case 'Y':
    122.                         text1after = text1after + 'Y';
    123.                         break;
    124.                     case 'Z':
    125.                         text1after = text1after + 'Z';
    126.                         break;
    127.                     case '0':
    128.                         text1after = text1after + '0';
    129.                         break;
    130.                     case '1':
    131.                         text1after = text1after + '1';
    132.                         break;
    133.                     case '2':
    134.                         text1after = text1after + '2';
    135.                         break;
    136.                     case '3':
    137.                         text1after = text1after + '3';
    138.                         break;
    139.                     case '4':
    140.                         text1after = text1after + '4';
    141.                         break;
    142.                     case '5':
    143.                         text1after = text1after + '5';
    144.                         break;
    145.                     case '6':
    146.                         text1after = text1after + '6';
    147.                         break;
    148.                     case '7':
    149.                         text1after = text1after + '7';
    150.                         break;
    151.                     case '8':
    152.                         text1after = text1after + '8';
    153.                         break;
    154.                     case '9':
    155.                         text1after = text1after + '9';
    156.                         break;
    157.                     case '.':
    158.                         text1after = text1after + '.';
    159.                         break;
    160.                     case '\'':
    161.                         text1after = text1after + '\'';
    162.                         break;
    163.                     case ',':
    164.                         text1after = text1after + ',';
    165.                         break;
    166.                     case '!':
    167.                         text1after = text1after + '!';
    168.                         break;
    169.                     case '?':
    170.                         text1after = text1after + '?';
    171.                         break;
    172.                     case ' ':
    173.                         text1after = text1after + ' ';
    174.                         break;
    175.                 default:
    176.                     text1after = text1after + '?';
    177.                     break;
    178.                 }
    179.  
    180.             }
    181.             arrayCounter++;
    182.             timeCounter = 0;
    183.         }
    184.     }
    185.    
    186.     void OnGUI(){
    187.         if(text1after != null){
    188.         if(guiCounter < text1after.Length){
    189.             switch(text1after[guiCounter]){
    190.                 case 'A':
    191.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    192.                     break;
    193.                 case 'B':
    194.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[1]);
    195.                     break;
    196.                 case 'C':
    197.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    198.                     break;
    199.                 case '\u00C7':
    200.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    201.                     break;
    202.                 case 'D':
    203.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    204.                     break;
    205.                 case 'E':
    206.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    207.                     break;
    208.                 case 'F':
    209.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    210.                     break;
    211.                 case 'G':
    212.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    213.                     break;     
    214.                 case '\u011E':
    215.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    216.                     break;
    217.                 case 'H':
    218.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    219.                     break;
    220.                 case 'I':
    221.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    222.                     break;
    223.                 case '\u0130':
    224.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    225.                     break;
    226.                 case 'J':
    227.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    228.                     break;
    229.                 case 'K':
    230.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    231.                     break;
    232.                 case 'L':
    233.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    234.                     break;
    235.                 case 'M':
    236.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    237.                     break;
    238.                 case 'N':
    239.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    240.                     break;
    241.                 case 'O':
    242.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    243.                     break;
    244.                 case '\u00D6':
    245.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    246.                     break;
    247.                 case 'P':
    248.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    249.                     break;
    250.                 case 'Q':
    251.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    252.                     break;
    253.                 case 'R':
    254.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    255.                     break;
    256.                 case 'S':
    257.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    258.                     break;
    259.                 case '\u015E':
    260.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    261.                     break;
    262.                 case 'T':
    263.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    264.                     break;
    265.                 case 'U':
    266.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    267.                     break;
    268.                 case '\u00DC':
    269.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    270.                     break;
    271.                 case 'V':
    272.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    273.                     break;
    274.                 case 'W':
    275.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    276.                     break;
    277.                 case 'X':
    278.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    279.                     break;
    280.                 case 'Y':
    281.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    282.                     break;
    283.                 case 'Z':
    284.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    285.                     break;
    286.                 case '0':
    287.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    288.                     break;
    289.                 case '1':
    290.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    291.                     break;
    292.                 case '2':
    293.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    294.                     break;
    295.                 case '3':
    296.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    297.                     break;
    298.                 case '4':
    299.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    300.                     break;
    301.                 case '5':
    302.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    303.                     break;
    304.                 case '6':
    305.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    306.                     break;
    307.                 case '7':
    308.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    309.                     break;
    310.                 case '8':
    311.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    312.                     break;
    313.                 case '9':
    314.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    315.                     break;
    316.                 case '.':
    317.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    318.                     break;
    319.                 case '\'':
    320.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    321.                     break;
    322.                 case ',':
    323.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    324.                     break;
    325.                 case '!':
    326.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    327.                     break;
    328.                 case '?':
    329.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    330.                     break;
    331.                 case ' ':
    332.                     GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    333.                     break;
    334.             default:
    335.                 GUI.DrawTexture(new Rect(offset*24, 54, 162, 600), theFont[0]);
    336.                 break;
    337.             }
    338.         }
    339.         guiCounter++;
    340.         offset++;
    341.         }
    342.     }
    343. }
    344.  
    345.  
     
    Last edited: Sep 3, 2012
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    As I already wrote, the whole switch makes your code unnecessarily hard to understand. I just took your code, removed a lot of variables, moved the switch into a new method and made a few changes that should resolve the issues. Just ask if you have any questions. but have look at the code with the switch statement moved into a separate method! One view and you already have a rough idea about what is going on!

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class TextController : MonoBehaviour {
    6.     public Texture2D[] theFont;
    7.  
    8.     private string text;
    9.     private int visibleCharactersCounter;
    10.     private float timeCounter;
    11.  
    12.     void Start() {
    13.         text = "HOW ARE YOU?";
    14.         visibleCharactersCounter = 0;
    15.         timeCounter = 0.0f;
    16.     }
    17.  
    18.     void Update() {
    19.         timeCounter += Time.deltaTime;
    20.         if(timeCounter >= 0.1f) {
    21.            
    22.                 // Make exactly one more character visible.
    23.             visibleCharactersCounter++;
    24.             timeCounter = 0.0f;
    25.            
    26.                 // But make sure that the number is not too big.
    27.             if (visibleCharactersCounter > text.Length) {
    28.                 visibleCharactersCounter = text.Length;
    29.             }
    30.         }
    31.     }
    32.    
    33.     void OnGUI(){
    34.        
    35.             // Draw each visible character.
    36.         for (int i = 0; i < visibleCharactersCounter; i++) {
    37.             GUI.DrawTexture(new Rect(i*24, 54, 162, 600), TextureFromCharacter (text[i]));
    38.         }
    39.     }
    40.    
    41.     private Texture2D TextureFromCharacter(char character) {
    42.        
    43.             // The whole switch stuff is now in here. There would probably be
    44.             // more elegant solutions for that.
    45.             // I stopped to increase the at character 'K'.
    46.    
    47.         switch(character){
    48.             case 'A':
    49.                 return (theFont[0]);
    50.             case 'B':
    51.                 return (theFont[1]);
    52.             case 'C':
    53.                 return (theFont[2]);
    54.             case '\u00C7':
    55.                 return (theFont[3]);
    56.             case 'D':
    57.                 return (theFont[5]);
    58.             case 'E':
    59.                 return (theFont[6]);
    60.             case 'F':
    61.                 return (theFont[7]);
    62.             case 'G':
    63.                 return (theFont[8]);     
    64.             case '\u011E':
    65.                 return (theFont[9]);
    66.             case 'H':
    67.                 return (theFont[10]);
    68.             case 'I':
    69.                 return (theFont[11]);
    70.             case '\u0130':
    71.                 return (theFont[12]);
    72.             case 'J':
    73.                 return (theFont[13]);
    74.             case 'K':
    75.                 return (theFont[14]);
    76.             case 'L':
    77.                 return (theFont[0]);
    78.             case 'M':
    79.                 return (theFont[0]);
    80.             case 'N':
    81.                 return (theFont[0]);
    82.             case 'O':
    83.                 return (theFont[0]);
    84.             case '\u00D6':
    85.                 return (theFont[0]);
    86.             case 'P':
    87.                 return (theFont[0]);
    88.             case 'Q':
    89.                 return (theFont[0]);
    90.             case 'R':
    91.                 return (theFont[0]);
    92.             case 'S':
    93.                 return (theFont[0]);
    94.             case '\u015E':
    95.                 return (theFont[0]);
    96.             case 'T':
    97.                 return (theFont[0]);
    98.             case 'U':
    99.                 return (theFont[0]);
    100.             case '\u00DC':
    101.                 return (theFont[0]);
    102.             case 'V':
    103.                 return (theFont[0]);
    104.             case 'W':
    105.                 return (theFont[0]);
    106.             case 'X':
    107.                 return (theFont[0]);
    108.             case 'Y':
    109.                 return (theFont[0]);
    110.             case 'Z':
    111.                 return (theFont[0]);
    112.             case '0':
    113.                 return (theFont[0]);
    114.             case '1':
    115.                 return (theFont[0]);
    116.             case '2':
    117.                 return (theFont[0]);
    118.             case '3':
    119.                 return (theFont[0]);
    120.             case '4':
    121.                 return (theFont[0]);
    122.             case '5':
    123.                 return (theFont[0]);
    124.             case '6':
    125.                 return (theFont[0]);
    126.             case '7':
    127.                 return (theFont[0]);
    128.             case '8':
    129.                 return (theFont[0]);
    130.             case '9':
    131.                 return (theFont[0]);
    132.             case '.':
    133.                 return (theFont[0]);
    134.             case '\'':
    135.                 return (theFont[0]);
    136.             case ',':
    137.                 return (theFont[0]);
    138.             case '!':
    139.                 return (theFont[0]);
    140.             case '?':
    141.                 return (theFont[0]);
    142.             case ' ':
    143.                 return (theFont[0]);
    144.             default:
    145.                 return (theFont[0]);
    146.         }
    147.     }
    148. }
     
  20. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Wow now I tried this, and it worked well. Thanks for the help. It is a less confusing script than mine. I was confused as I say "oh I can use for loop but if I use it, one letter will be invisible at one frame". If you don't understand what I mean, don't worry, I was confused. :D Whatever, I have to ask some questions:
    1-Which University Department did you study?
    2-Can I make the font as font sheet? That font list looks messy. I heard, DrawTexture can't set the offset of texture, because it is not a material.
    3-Thanks for your help, how did you write it so quickly. :D
     
  21. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That has nothing to do with a grade, it's a lot of practice!

    Such decision always depend on the project. What is your goal? Is it a learning project or do you want to publish something for a mobile? Right now, it's even harder than usual, because the new GUI for Unity will probably be released within several months.
    Personally, I would do it with NGUI, because your problem is pretty much solved in it, but it cost you about 100 USD.
    In about 6 month, I will tell you to use the new GUI from Unity (hopefully).

    Indeed, DrawTextureWithTexCoords may be a better solution.

    I knew what you wanted to achieve. The solution how this should be done already existed in my mind before I even started to edit your code.
     
  22. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Thanks for the first answer. Now I believe that I can be successful in programming if even I don't study programming in University(Can I???). Unity Community is helpful too. DrawTextureWithTexCoords will do the job I think. I will try someday. I don't want to spend 100 USD anyway. :D But actually I don't get it why you asked me that if it is learning project or mobile game? And what is the new GUI, why it is harder I don't get it. o_O Are you talking about 100 USD GUI or other new GUI? And actually I know what I want to do before starting program something but then I get slower. :D Looks like I need a lot of practice. Thanks anyway. ^_^ DrawTextureWithTexCoords will be good for this. Project is getting smaller, yehoow.
     
  23. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I wanted to say, if you need a really good solution now, I would propose you to use NGUI. If you are just experimenting, that is certainly not needed.
    In some month, Unity 4 will come and in Unity 4.1 there should be a new GUI system, that one won't cost you anything as it is going to be a part of Unity.
     
  24. Sphynxinator

    Sphynxinator

    Joined:
    Jan 22, 2011
    Posts:
    44
    Wow good. DrawTextureWithTexCoords will be good solution actually. Thanks.