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 Xylophilia · Aug 11, 2013 at 03:01 PM · basics

Scripting Shortcuts

Hi, I'm learning to script, just getting used to few things around here and there.

If I wanted to use gameObject.renderer.material.color often, can't I just set the whole thing equal to "Color" somehow?

So I tried Color = gameObject.renderer.material.color

I forgot how to make those Shortcuts. Can somebody help me?

  • I just want to be able to use the whole sentence without having to type it out every single time. Do you get me?

I remember watching a tutorial video about it. Someone used a shortened version of narrowing things down, so for example, "Cube Color" instead of renderer.material.color.

He said that would be less messy & faster for Unity to read...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by -hiTo- · Aug 11, 2013 at 03:15 PM

Color variableName = gameObject.renderer.material.color;

Not sure if this is what you are looking for, as it is pretty trivial scripting...

If on the other hand you want to CHANGE gameObject.renderer.material.color often, then no, there is no shortcut, other than defining a new Color, changing it and then setting the material.color to that newly defined Color at the end of the function.

Also, gameObject is unnecessary to type out. renderer.material.color is enough.

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 Xylophilia · Aug 11, 2013 at 03:26 PM 0
Share

I just want to be able to use the whole sentence without having to type it out every single time. Do you get me?

I remember watching a tutorial video about it. Someone used a shortened version of narrowing things down, so for example, "Cube Color" ins$$anonymous$$d of renderer.material.color.

He said that would be less messy & faster for Unity to read...

avatar image -hiTo- · Aug 11, 2013 at 04:48 PM 0
Share
 Color matCol = renderer.material.color;
 
 Debug.Log(matCol);
 Debug.Log(renderer.material.color);

Both of the Log-functions will return the same value.

However, if you want to assign a value to renderer.material.color;

You make a property or function that will change the value of that property when another value is changed.

e.g.

 private Color _matCol;
 
 private Color matCol
 {
     get { return _matCol; }
     set { _matCol = value; renderer.material.color = value; }
 }
 
 //If you do it like that, you can change
 //renderer.material.color by changing matCol, like so:
 
 private void ChangeColor()
 {
     matCol = new Color(0.5f, 0.5f, 0.5f);
     //renderer.material.color is now 0.5f, 0.5f, 0.5f
 }

But that seems to be an awful workaround just to not type three words.

$$anonymous$$ost definitely, you are making a way too big of an issue of a simple thing. And I believe the first example will be of more use than the second.

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

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

basic scripting 3 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