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 Tap1 · Dec 04, 2017 at 05:12 PM · gameobjectdistancealphatransparentbyte

Why gameobject is not transparent on Android version?

I have racing game where opponent is transparent when he is close enough. There is codes: //Check how far other is and make ghost more transparent if close. float distance = Vector3.Distance(formulaMainPart.GetComponent().position, ghostMainPart.GetComponent().position);

             distance *= 15;
 
             if (distance >= 255)
             {
                 if (!opaque)
                 {
                     opaque = true;
                     trasparent = false;
                     SetMaterialOpaque();
                 }
             }
             else
             {
                 if (!trasparent)
                 {
                     trasparent = true;
                     opaque = false;
                     SetMaterialTransparent();
               }
                 ghostMainPart.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
                 ghostTire1.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
                 ghostTire2.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
                 ghostTire3.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
                 ghostTire4.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
             }  


 private void SetMaterialTransparent()
 
     {
 
         foreach (Material m in ghostMainPart.GetComponent<Renderer>().materials)
 
         {
 
             m.SetFloat("_Mode", 2);
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
 
             m.SetInt("_ZWrite", 0);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.EnableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = 3000;
 
         }
 
         foreach (Material m in ghostTire1.GetComponent<Renderer>().materials)
 
         {
 
             m.SetFloat("_Mode", 2);
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
 
             m.SetInt("_ZWrite", 0);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.EnableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = 3000;
 
         }
 
         foreach (Material m in ghostTire2.GetComponent<Renderer>().materials)
 
         {
 
             m.SetFloat("_Mode", 2);
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
 
             m.SetInt("_ZWrite", 0);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.EnableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = 3000;
 
         }
 
         foreach (Material m in ghostTire3.GetComponent<Renderer>().materials)
 
         {
 
             m.SetFloat("_Mode", 2);
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
 
             m.SetInt("_ZWrite", 0);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.EnableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = 3000;
 
         }
 
         foreach (Material m in ghostTire4.GetComponent<Renderer>().materials)
 
         {
 
             m.SetFloat("_Mode", 2);
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
 
             m.SetInt("_ZWrite", 0);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.EnableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = 3000;
 
         }
     }
 
 
 
     private void SetMaterialOpaque()
 
     {
 
         foreach (Material m in ghostMainPart.GetComponent<Renderer>().materials)
 
         {
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 
             m.SetInt("_ZWrite", 1);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.DisableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = -1;
 
         }
         foreach (Material m in ghostTire1.GetComponent<Renderer>().materials)
 
         {
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 
             m.SetInt("_ZWrite", 1);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.DisableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = -1;
 
         }
 
         foreach (Material m in ghostTire2.GetComponent<Renderer>().materials)
 
         {
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 
             m.SetInt("_ZWrite", 1);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.DisableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = -1;
 
         }
 
         foreach (Material m in ghostTire3.GetComponent<Renderer>().materials)
 
         {
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 
             m.SetInt("_ZWrite", 1);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.DisableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = -1;
 
         }
 
         foreach (Material m in ghostTire4.GetComponent<Renderer>().materials)
 
         {
 
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 
             m.SetInt("_ZWrite", 1);
 
             m.DisableKeyword("_ALPHATEST_ON");
 
             m.DisableKeyword("_ALPHABLEND_ON");
 
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 
             m.renderQueue = -1;
 
         }
     }

This is working fine in computer but when I use it on android phone it is not working. I can see that gameobject is transparent but alfa is not changing. Do someone know whats wrong with this. I tested that distance is same on android and pc but I think there might be something wrong with (byte) distance command.

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 Tap1 · Dec 05, 2017 at 09:25 AM 0
Share

Anyone know what might be problem?

0 Replies

· Add your reply
  • Sort: 

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

148 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

Related Questions

Player Can't hit enemy 0 Answers

Get the lowest value from a Gameobject List 0 Answers

How to check distance between a specific object and every objects in a list ?,How can I check the distance between an object and every objects in a list ? 1 Answer

how to use vectors to control an outcome 0 Answers

Consistent spacing between gameobjects when some disabled 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