Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is there a way to dynamically create a texture/material that is a number and attach it to an object?

Discussion in 'Scripting' started by voidraizer, Dec 13, 2014.

  1. voidraizer

    voidraizer

    Joined:
    Dec 20, 2013
    Posts:
    6
    To be more specific, I made a nice glass container that has some large flattish plates inside that spin around. I create a number of little balls on the inside and the plates mix them all up. Then I have it so you press a button and one ball falls out the bottom and rolls over to you. Is there a way to create and assign a material to each ball as they're created? I'd like to create a material that has a number "1", then "2", then "3" and so on so each ball has a number on it as you probably guessed by now. Is there a way to create the materials with a design like that on the fly? I'm looking for a way to not have to create 300 textures with just a number on it.

    Here's my very generic instantiation code in case it helps

    balls = new GameObject[numberOfBalls];
    for( int i = 0; i < numberOfBalls; i++ )
    {
    balls(i) = (GameObject)Instantiate( ballPreFab, new Vector3( Random.Range( -1.3f, 1.3f ), Random.Range( 4.5f, 6.5f ), Random.Range( 1.8f, 4.2f ) ), Quaternion.identity );
    }
    I don't know why but putting 'i' in brackets next to balls won't show up so I used parenthesis instead.
     
  2. OpticalOverride

    OpticalOverride

    Joined:
    Jan 13, 2013
    Posts:
    161
  3. voidraizer

    voidraizer

    Joined:
    Dec 20, 2013
    Posts:
    6
    This looks like exactly what I needed thank you!