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 unity_Vpi53N_fb99F6g · Apr 01, 2020 at 05:38 PM · colorimagevisual studio

Can't access image color

This is so weird because Visual Studio says that Image does not contain a definition for color, but clearly it does.

Here's the whole code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class RadialMenu : MonoBehaviour
 {
     public Transform radialMenu;
     public List<RadialButton> buttons = new List<RadialButton>();
 
     private Vector2 mousePos;
 
     private int selectedItem;
     private int oldItem;
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         UpdateMenu();
     }
 
     void UpdateMenu()
     {
         //Gets the mouse position between 0,1
         mousePos = new Vector2(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height);
 
         //Gets the angle the mouse is in
         float angle = ((Mathf.Atan2(.5f, 0) - Mathf.Atan2(mousePos.y - .5f, mousePos.x - .5f)) * Mathf.Rad2Deg) % 360;
 
         selectedItem = (int)(angle / (360 / buttons.Count));
 
         if(selectedItem != oldItem)
         {
             buttons[oldItem].image.color = buttons[oldItem].normalColor;
         }
     }
 }
 
 public class RadialButton
 {
     public string name = "Button" + Random.Range(0, 100);
     public Image image;
     public Color normalColor = Color.gray;
     public Color highLightedColor = new Color(.4f, .4f, .4f, 1);
 
 }
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 Hellium · Apr 02, 2020 at 07:44 AM 0
Share

Are you sure you don't have a custom class / struct called Image in your project?


Right click on the Image word in Visual Studio then > Go to definition. If it's not Unity's image, you will have to specify the complete name of the class to avoid confusion:

  public UnityEngine.UI.Image image;
avatar image unity_Vpi53N_fb99F6g Hellium · Apr 02, 2020 at 04:50 PM 0
Share

Yeah, that was the problem, thanks so much

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by unity_Vpi53N_fb99F6g · Apr 28, 2020 at 06:44 PM

The problem was I had another class called Image.

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 GrayLightGames · Apr 02, 2020 at 05:21 AM

Debug.Log may help you solve this... first I would check the value of oldItem (it should be zero unless you initialized it somewhere else). Then I would check if buttons[oldItem] is null. Then check which button it is by checking the name. Then check if the Image attached to buttons[oldItem] is null, and maybe even check image.name to see if it has the intended Image object attached. I copied your code to an empty script, it didn't throw an error so I'm assuming it's giving you an error at runtime. Hope that helps!

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 unity_Vpi53N_fb99F6g · Apr 02, 2020 at 08:22 AM 0
Share

Thanks so much for the response, but the error is not at runtime, although you did save me a lot of trouble since the list was null, and that would've given me a lot of errors later on.

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

133 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

How to store colors for future use 2 Answers

How to access color & texture functions of a "RawImage Script" simontaneously?? 0 Answers

Change the button target image alpha 1 Answer


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