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
1
Question by PrestonCD · May 16, 2014 at 11:45 PM · materialc #

How to make a Transparent GameObject?

I have this script for making the material transparent. Is it right? Also it gives me this error: Assets/MyGame/Transparent.cs(6,46): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration using UnityEngine; using System.Collections;

 public class Transparent : MonoBehaviour
 {
     gameObject.renderer.material.color.a = 1;
 }

Idk whats wrong with it though. Any answer helps :D

Comment
Add comment · Show 1
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 MFKJ · Apr 20, 2020 at 11:51 AM 0
Share

Its simple https://youtu.be/q7jE569IkQs

2 Replies

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

Answer by Jeff-Kesselman · May 16, 2014 at 11:51 PM

Um.

Lots.

FIRST off, you can't just have code sitting in a C# class. It needs to be in a method. In this case, probably the Start method

 public class Transparent : MonoBehaviour
 {
     void Start(){
        gameObject.renderer.material.color.a = 1;
     }
 }




Secondly, you probably can't set the color that way. Color is likely a struct which means you probably have to set gameObject.renderer.material.color to a complete color.

 public class Transparent : MonoBehaviour
 {
     void Start(){
        gameObject.renderer.material.color= 
               new Color(1.0f,1.0f.1.0f,1.0f);
     }
 }

THIRD, alpha of 1.0 is fully opaque, you want something less then 1 if you want it to be translucent.

FOURTH, it wont work anyway unless you have a transparent renderer set.

Comment
Add comment · Show 5 · 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 PrestonCD · May 17, 2014 at 12:03 AM 0
Share

Ok thanks, well now its giving me this: Assets/$$anonymous$$yGame/Trans.cs(11,53): error CS1526: A new expression requires () or [] after type

If you you can, how would i add a transparent renderer would it just be

 gameObject.renderer.transparent.material.color=


?

avatar image MikeNewall · May 17, 2014 at 12:40 AM 0
Share

You'll need to apply a transparent diffuse shader to your object too in order for transparency to work.

avatar image PrestonCD · May 17, 2014 at 12:50 AM 0
Share

Im completely new to Unity, so i have no idea on how to do this :/

avatar image MikeNewall · May 17, 2014 at 01:01 AM 0
Share

Create a new material and choose the Transparent Diffuse shader from the shader dropdown box. Then drag it onto your object in the scene.

Use @Jeff-$$anonymous$$esselman example to change the alpha by code, or you can do it in the inspector.

https://docs.unity3d.com/Documentation/Components/shader-TransDiffuse.html

avatar image PrestonCD · May 17, 2014 at 01:22 AM 0
Share

Finally it works! Thanks so much!

avatar image
5

Answer by Gords · May 24, 2016 at 02:15 PM

i dont know if im missing something, or maybe is a new feature in unity 5 but i just selected "Rendering Mode: Transparent" inside my material, then assigned it to my gameObject and, thats it.

Comment
Add comment · Show 3 · 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 Jeff-Kesselman · May 24, 2016 at 11:20 PM 0
Share

This is pre "physically based rendering". Setting the shaders has changed a bit yes, but the rest should still apply.

avatar image guneyozsan · Jun 04, 2016 at 05:32 PM 0
Share

I think it is changed in Unity 5. Transparent Diffuse: "Unity 5 introduced the Standard Shader which replaces this shader."

avatar image visioneers · Aug 31, 2016 at 06:03 PM 0
Share

I did this and it worked too. What I neglected to do at first was to change the alpha of the color after setting this.

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

28 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

Related Questions

Multiple Cars not working 1 Answer

Using Multiple Tiles for Textures 0 Answers

Audio Fades 1 Answer

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

Primitive block texturing (In code) HELP 0 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