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 Hoffa25 · Nov 25, 2014 at 08:33 AM · imagechange

How to change an images source image from script? C#

I have been stuck on this for several hours now and I cant find any answer that I understand here or on google:/. Being a beginner at Unity and C# please try to explain for an idiot:)

I have my Image "testImage" decleared in my script and I have dragged the Image gameobject to the slot in inspector. In my project assets I have the other source image that I want to change to called "NewSourceImage".

   public Image testImage;
     
   public void Change()
     
     {
       testImage = GetComponent<Image>("NewSourceImage");
     }

I get the error message: error CS0308: The non-generic method `UnityEngine.Component.GetComponent(System.Type)' cannot be used with the type arguments

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 Hoffa25 · Nov 25, 2014 at 10:29 AM 0
Share

Ok, thanks but I tried as you wrote and get this error message now:

error CS0308: The non-generic method `UnityEngine.Component.GetComponent(System.Type)' cannot be used with the type arguments

avatar image CHPedersen · Nov 25, 2014 at 10:35 AM 0
Share

You're passing type parameters to a method that is not generic. Update your question with the changes you made to your code, or we have no chance to fix it. This isn't Delphi, and I'm not the oracle of it. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by CHPedersen · Nov 25, 2014 at 08:34 AM

In C#, there should be no period before the type parameter brackets:

 testImage = GetComponent<Image>("NewSourceImage");
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

is this correct way to change var from other script? 1 Answer

Is it possible to change an images source image by code? C# 2 Answers

The variables and functions 2 Answers

Any runtime image file browsers available? 1 Answer

Changing GameObject texture? 4 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