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
0
Question by mcfishbomb · Jan 19, 2013 at 09:15 AM · texture2dguitextureresourcesloadassetatpath

How to change the image (texture) of a GUITexture in C#.

I am making a game, and the player has multiple weapons, and I want to display which weapon is being used. I made two pictures to show which picture is being used. But I have no idea how to make it switch from one to another. I understand how to access the GUITexture, but I don't understand how to access the Texture that is in my assets folder. This is the code I am currently using, but I don't know what's going wrong.

GameObject.Find("Weapon").guiTexture.texture = Resources.Load("sword") as Texture2D;

The image is names "sword". If you find a URL to my problem, please link me to it, but I could not find an answer.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Imankit · Jan 19, 2013 at 09:47 AM

 public GameObject weapon;      // drag your GUITexture object here in inspector
 
 // When you want to change the texture...
 
 weapon.GetComponent<GUITexture>().texture = Resources.Load("sword") as Texture2D;       // This is for C#
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 mcfishbomb · Jan 19, 2013 at 06:27 PM 0
Share

I tried that and it worked even worse than before. Before, the image disappeared, so the GuiTexture was connected, but now the image doesn't even disappear. Really all I'm looking for is how to change the right side with resources.load to make it work.

avatar image Imankit · Jan 21, 2013 at 04:48 AM 0
Share

In which folder your Texture is if its in Resources folder then it should have worked..

avatar image
0

Answer by JPLKit · Mar 27, 2014 at 03:55 PM

but I don't understand how to access the Texture that is in my assets folder.

You want to create a folder called Resources inside your Assets folder and put your image(s) inside the Resources folder. (Capital R in resources is important)

Then you can use Resources.Load();

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
0

Answer by blenderblender · Nov 02, 2014 at 10:10 AM

  using UnityEngine;
 using System.Collections;
 
 public class GUIController : MonoBehaviour {
 
 public Texture2D yourtexture;
 // Use this for initialization
 void Start () {
 }
 // Update is called once per frame
 void Update () {
 }
 void OnGUI()
 {
 GUI.DrawTexture(new Rect(10,10,60,60), yourtexture);
 }
 }
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

12 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

Related Questions

GUI Texture vs Texture2D: which one 1 Answer

How to get a Texture asset that is in the project and pass it to a function? 3 Answers

Assigning script-generated textures 0 Answers

create a GUITexture through script 1 Answer

Best way to show an image 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