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 /
  • Help Room /
avatar image
0
Question by JaredHD · Dec 14, 2016 at 07:33 PM · c#texturestransparency

Adjust Trees transparency/Opaque/Alpha value

I've made the following script that determines if something is blocking the cameras view of the player

if (Physics.Raycast(player.position, targetMove - player.position, out hit, Vector3.Distance(player.position, targetMove)))

     {
         //if the last raycast hit is not the same as the new one (E.g. Monster to rock) set Monster to 100% transparency (can see)
         if (hit.transform.gameObject.tag != "Terrain")
         {
             if (oldGameobject.name != hit.transform.gameObject.name)
             {
                 oldGameobject = hit.transform.gameObject;
                 color.a = 1;
             }

             //Get render of the Gameobject
             render = hit.transform.gameObject.GetComponentInChildren<Renderer>();
             mat = render.material;
             color = mat.color;

             //If alpha value is greater then subtract
             if (color.a > 0.7f)
             {
                 color.a -= 0.1f;
             }
             mat.color = color;
             //targetMoveUse = Vector3.Lerp(hit.point, player.position, rayHitMoveInFront);
         }

Now this works on one of my monster characters using a custom shader, (Textures don't allow adjusting the opaque/alpha value by default) As you can see Below the monster is slightly Transparent (you can see the players legs)

alt text

Now here is the tree which isn't transparent, any help would be greatly appreciated

(I got the Idea from a game called Titan Quest) alt text

effect.png (141.0 kB)
effect2.png (378.1 kB)
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
0
Best Answer

Answer by JaredHD · Dec 16, 2016 at 01:25 PM

I've figured it out. All ownership of the code goes to Panthesilea, http://answers.unity3d.com/questions/694727/unity-tree-transparency.html

Here is the code that made it work but it requires editing unity's default trees. i deleted the LODs in the tree and picked one of the trees (child of the tree and made it the parent), I then created a raycast from the camera to the player and determined if something was in front of the camera and if the tag was equal to a tree I then ran the following code.

 private void SetTransparent(GameObject g)
      {
          for (int i = 0; i < g.renderer.materials.Length; i++)
          {
              g.renderer.materials[i].shader = Shader.Find("Transparent/Diffuse");
              g.renderer.materials[i].SetColor("_Color", new Color(1, 1, 1, 0.1f));
          }
          for (int i = 0; i < g.transform.childCount; i++)
              SetTransparent(g.transform.GetChild(i).gameObject);
      }
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 randytayler · Mar 04, 2017 at 03:48 PM

I'm having trouble with mobile, the same one described by @Panthesilea. My trees are all turning purple when I try to restore them to opaque after having made them transparent. He mentions using a Resources folder, but I don't follow -- and his post is pretty old. Did you have to solve that problem, @JaredHD?

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 JaredHD · Mar 05, 2017 at 11:47 AM 0
Share

There were 2 ways to do it if i remember correctly. Create a folder caller Resources and place it in there or what i did was go to "Edit->Project Settings->Graphics." Inside there, you'll find something called "Always included shaders". Add your shader to that

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

277 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Mobile Optimization: Transparent Textures vs Different Meshes 0 Answers

Score Points based on Animating Png Texture 2 Answers

Reading from RWTexture2D in compute shader Unity 0 Answers

Healthbar creation without using UI, only with images/TEXTURE 0 Answers

Real Time Video transparency by adding Pixels? 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