Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate prefab (Resources.Load) 1 Answer

Resources.Load Problem 1 Answer

How to assign different TEXTURES to objects with the same mesh? 1 Answer

Resources.Load Instantiate Yield problems 1 Answer

Load multiple instances of a prefab through code 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges