Unity Box Assignment part 2

So, if you remember, in the last post I wrote about an assignment I had for one of my classes on making a scene in Unity and having a script assign a color to the box. This week, we were given a follow-up assignment in which we were to add to our previous build and make a script that would essentially store each color from each box in an array and then allow you to recall the color from that box and place it back on that same box. The following is a video showing my final product and the functionality. As I state in the video, there is a bug that no matter what I did, I could not get it to go away. 


The following is the script I used for this assignment.



var objects : GameObject[];

var originalColor : Color[];

function Start ()
{
         
       originalColor = new Color[10];
      
       originalColor[0] = GameObject.Find("Cube0").renderer.material.color;
       originalColor[1] = GameObject.Find("Cube1").renderer.material.color;
       originalColor[2] = GameObject.Find("Cube2").renderer.material.color;
       originalColor[3] = GameObject.Find("Cube3").renderer.material.color;
       originalColor[4] = GameObject.Find("Cube4").renderer.material.color;
       originalColor[5] = GameObject.Find("Cube5").renderer.material.color;
       originalColor[6] = GameObject.Find("Cube6").renderer.material.color;
       originalColor[7] = GameObject.Find("Cube7").renderer.material.color;
       originalColor[8] = GameObject.Find("Cube8").renderer.material.color;
       originalColor[9] = GameObject.Find("Cube9").renderer.material.color;
       //color\cube array information above
      
       // Debug.Log(originalColor[3] + " " + originalColor[1]); //debugging log for original color information issue
       
}

var target : GameObject;
//var h : GameObject;
function Update () {

     if (Input.GetKeyDown("1"))
       {
                   //var lengthTwo = objects.length;
                   //Debug.Log("TestTwo " + lengthTwo);
                   //debug log for function update and input info
                  
                   target = GameObject.Find("Cube0");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[0];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("2"))
       {
                target = GameObject.Find("Cube1");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[1];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("3"))
       {
               target = GameObject.Find("Cube2");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[2];

                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("4"))
       {
                target = GameObject.Find("Cube3");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[3];
                   }else{
                       target.transform.renderer.material.color = Color.white;   
                      
                   }
       }
       if (Input.GetKeyDown("5"))
       {
                target = GameObject.Find("Cube4");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[4];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("6"))
       {
                target = GameObject.Find("Cube5");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[5];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("7"))
       {
                   target = GameObject.Find("Cube6");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[6];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("8"))
       {
                   target = GameObject.Find("Cube7");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[7];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("9"))
       {
                   target = GameObject.Find("Cube8");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[8];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       if (Input.GetKeyDown("0"))
       {
                   target = GameObject.Find("Cube9");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[9];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
       }
       /*if (Input.GetKeyDown("p"))
       {
                   target = GameObject.Find("Cube99");
                  
                   if(target.renderer.material.color == Color.white)
                   {
                       target.transform.renderer.material.color = originalColor[10];
                   }else{
                       target.transform.renderer.material.color = Color.white;
                   }
                   //above was a test constraint during debugging session
           }*/
}

Also, I forgot to mention it in my video, but I have to give a HUGE shout out to my good and dear friend Brent. He helped me significantly with this assignment and getting the thing as bug free as possible.

Comments

Popular posts from this blog

CSG-115 Tools of the trade