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 LuftWaffle3 · May 10, 2018 at 03:49 PM · scripting problemscript.color

I cant find out what will fix this code it has stumped me for a week now with no solution that I can find

using UnityEngine; using System.Collections; using System;

public class ChangeAlpha : MonoBehaviour {

 void Update ()
 {
     if(Input.GetKeyUp(KeyCode.T))
     {
         StartCoroutine(FadeTo(0.0f, 1.0f));
     }
     if(Input.GetKeyUp(KeyCode.F))
     {
         StartCoroutine(FadeTo(1.0f, 1.0f));
     }
 }

 IEnumerator FadeTo(float aValue, float aTime)
 {
     float alpha = transform.renderer.material.color.a;
     for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / aTime)
     {
         Color newColor = new Color(1, 1, 1, Mathf.Lerp(alpha,aValue,t));
         transform.renderer.material.color = newColor;
         yield return null;
     }
 }

} this is my code and the lines that say renderer.material.color give me error code CS1061

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kciwsolb · May 10, 2018 at 04:37 PM

Try using: float alpha = GetComponent<Renderer>().material.color.a;

And try using: GetComponent<Renderer>().material.color = newColor;

That error occoccurs when you try to call a method or access a class member that does not exist.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1061

In this case, GameObject.renderer was removed in version 2018.1.0. So you must change how you reference it (like I showed you above).

https://docs.unity3d.com/ScriptReference/GameObject-renderer.html

Also make sure you are using a rendering mode on your material (check the top of the inspector when you select your material) that supports transparency. The default is opaque. Change it to something else.

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 LuftWaffle3 · May 11, 2018 at 02:53 PM 0
Share

@$$anonymous$$ciwsolb How do I find the material for a 3d model that I downloaded?

avatar image Kciwsolb LuftWaffle3 · May 11, 2018 at 03:36 PM 0
Share

Click on your object, find the material in the inspector, if it is using the default standard shader, make sure it is using transparent or fade for the rendering mode.

But anyways, my original answer answers your main question, which was why you were getting an error. So, if you change what I said above, it should compile. The last part of my answer and this response was just a suggestion of a way you could work around that if your material was using the default shader.

avatar image
0

Answer by JonPQ · May 10, 2018 at 04:28 PM

Which line is the error, reading color or writing it ? if its reading, then maybe the object you are running this on, does not have a renderer, or material. add some checks in the code to check for nulls Is it a sprite ? or Ui object, most of those have no material.

If it is causing error in writing the color, maybe you have an invalid number in there... print out the color you are trying to write with debug log. (temporarily) before you try assigning it. also try running debugger, and stepping through line by line, checking what all the values are.

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

150 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 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

A Javascript trying to access an image effect C# script 1 Answer

Change emission with script 0 Answers

Some scripts have compilation errors which may prevent obsolete API usages to get updated. Obsolete API updating will continue automatically after these errors get fixed. 0 Answers

Why i'm getting UnassignedReferenceException when running the game ? 1 Answer

How can i get in real time the speed movement of each camera ? 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