- Home /
 
               Question by 
               BomjBomj · Jun 12, 2019 at 04:13 PM · 
                textureinstantiateresources.load  
              
 
              Problem with missing texture with Instantiate( Resources.load ) method
Hello guys, I have a problem where a Instantiate a cube and set it's texture. WIth this I have no problem, but when I try to move the cube, it loses it's texture. Where am I wrong with my code?
Here is code:
 int lastPic;
 public GameObject pic1, pic2, pic3, pic4, pic, buttonsCanvas;
 Vector3 velocity = new Vector3(0, 0, -10);
 Texture texture, textureClone;
 bool flag = false;
 bool timerStarted = false;
 void Start()
 {
     
     SetPicture();
     
 }
 void Update()
 {
     
     if (GameObject.FindGameObjectsWithTag("GreyCube").Length == 0 && !flag)
     {
         pic.transform.position += velocity * Time.deltaTime;
         pic.transform.localScale = new Vector3( 18.8f, 11, 0);
     }
     
     if (pic.transform.position.z < 1.5f && !flag)
     {
         pic.transform.position = new Vector3( 0, 1, 1 );
         flag = true;
         pic.transform.localScale = new Vector3(19, 11, 0);
         PlayerPrefs.SetInt("LastPic", PlayerPrefs.GetInt("LastPic", 1) + 1);
     }
 }
 public void SetPicture()
 {
     PlayerPrefs.SetInt("LastPic", 0);// For Debug
     lastPic = PlayerPrefs.GetInt("LastPic", 0);
     if (lastPic < 10)
     {
         pic = Instantiate(pic1, new Vector3(0, 1, 16), Quaternion.identity);
         pic.transform.Rotate(0, 0, 180);
     }
     else if (lastPic < 20)
     {
         pic = Instantiate(pic2, new Vector3(0, 1, 16), Quaternion.identity);
         pic.transform.Rotate(0, 0, 180);
     }
     else if (lastPic < 30)
     {
         pic = Instantiate(pic3, new Vector3(0, 1, 16), Quaternion.identity);
         pic.transform.Rotate(0, 0, 180);
     }
     else
     {
         pic = Instantiate(pic4, new Vector3(0, 1, 16), Quaternion.identity);
         pic.transform.Rotate(0, 0, 180);
     }
     texture = Resources.Load<Texture>("images/" + "(" + lastPic.ToString() + ")");
     textureClone = Instantiate(texture);
     pic.GetComponent<MeshRenderer>().material.mainTexture = textureClone;
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                