• 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 /
  • Help Room /
avatar image
0
Question by Zitoox · Jul 30, 2016 at 10:15 PM · texturematerialchangeonmouseup

Change cube texture script

Hi! As i said many times, i am a beginner at scripting. I am starting to understand things, but i only know the basics =P

So, i was asking myself: I need to learn! How am i going to finish a game if i can't make scripts for it? So, i created a new project ONLY to train my skills. I made a very nice "computer sim". Currently you can look around your desk and turn on the pc. But i want to make a "texture changer script" and i don't know how =/

Is it possible to make a script that can CHANGE some specific cubes' textures when you click on it using the mouse?

Here's the script i have for now. (I know, it's ridiculous but i made it just to test if it work)

 #pragma strict
 
 function OnMouseUp()
 {
     Debug.Log("The system started");
 }

It displays a message on the console when the player click on the "START" button. When the player press the start button, i want a cube to change it's texture. Actually, more than one cube. I have some things in mind,like... i know that i need to use variables so i can select the cubes more easily, but the thing about change the textures...

Comment
Add comment · Show 1
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
avatar image Zitoox · Jul 30, 2016 at 10:40 PM 0
Share

G O I N G U P

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Jul 31, 2016 at 02:12 AM

      // find your cube in the scene and assign it to a variable
      var cube1:GameObject;
      cube1=gameObject.Find("the name of your cube here");
      
  //leave a space in the inspector where you can drag and drop animage
         
      var sometexture:Texture2D;
          if (!sometexture){sometexture=new Texture2D(2,2);}
      
      // this is the line to change the texture of an object!!!
      // put this line wherever you want the change to happen!!!
      
      cube1.transform.renderer.material.mainTexture=sometexture;
 
 
Comment
Add comment · Share
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

62 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

Related Questions

Problem with a transparent texture in an object that already has a material 0 Answers

Material Rendering Bug 0 Answers

Texture issue 0 Answers

Implement a texture to a object like a decal and try to Rotate/Move/Scale 0 Answers

Car Customization -1 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