Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by gianni123 · May 12, 2012 at 07:38 AM · textureguitexturechange

Change texture of GUItexture from script

hi, how to change texture of GUItexture with the name of the texture?

something like this..

 var texturename="casualtexture";
 
 GameObject.Find(photo1).guiTexture.texture=texturename;
Comment
Add comment · Show 2
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 syclamoth · May 12, 2012 at 07:43 AM 1
Share

Accessing resources with their names alone is a bad idea in general. Why is it so necessary in this case? You should be able to find an object by its path given that it is in the Resources folder. Otherwise, you should either use a Dictionary of pairs linking textures with names (and then index that using the string), or just have a bunch of Texture variables that you can assign in the inspector.

avatar image gianni123 · May 12, 2012 at 07:52 AM 1
Share

is necessary because I take the names from an xml file..

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by NorthernEagle · May 18, 2012 at 09:07 PM

You can also assign Texture2D link as public variables and assign GuiTexture like that. For example:

( C# code follows )

public GuiTexture clickButton;
public Texture2D clickButtonTexture;

clickButton.guiTexture.texture = clickButtonTexture;

Comment
Add comment · Show 2 · 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
avatar image boddole · Feb 06, 2014 at 04:10 AM 0
Share

I'm co$$anonymous$$g in late, but I would like to say that your solution was exactly what I was looking for, thanks.

avatar image Requiem99 · Jul 09, 2014 at 11:19 AM 0
Share

Oh! thank you so much!!!

avatar image
1

Answer by gianni123 · May 12, 2012 at 08:57 AM

same problem for audiosource..

     var audioname="casualsound";
 GameObject.Find(audioplay).GetComponent("AudioSource").AudioClip=audioname;
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
avatar image
1

Answer by gianni123 · May 12, 2012 at 10:02 AM

SOLVED

I created the folder resources in assets

I put my image files inside..

var texturenameok=Resources.Load(texturename); GameObject.Find(photo1).guiTexture.texture=texture nameok;

Comment
Add comment · Show 1 · 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
avatar image GurtejKanwar · Aug 14, 2012 at 09:11 PM 1
Share

If this worked for you, you should probably accept this answer.

avatar image
0

Answer by LSPressWorks · Jul 25, 2014 at 05:00 PM

HA! I think this post just solved like, 3 problems for me! I had no idea UNITY did resources!

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Changing Object Texture When button is pressed. 3 Answers

Changing GameObject texture? 4 Answers

Changing texture for pause button 1 Answer

script help gameobject to playercar 1 Answer

referring to a particular material 0 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