- Home /
 
tranparent object
there is a way to create a touch button, on touch the 3d object get 50% transparence and touch again the 3d object came back to normal.
Answer by sirival · Nov 15, 2012 at 09:42 PM
Something like that?
 public class Button : MonoBehaviour 
 { 
 
   // the material of the object you want to make transparent      
   public Material objectMaterial;
 
   private void OnGUI() 
   { 
     if( GUILayout.Button( "Touch" ) ) 
     { 
       var color = objectMaterial.color;
       if( color.a <= 0.5f ) 
         color.a = 1;
       else 
         color.a = 0.5f
 
       objectMaterial.color = color;
 
      }
 
 }
 
              my object name is $$anonymous$$pot, where do i specified this?
Just pass the object's material as a reference to this script
i put iot like this. butt theres errors.
is a 3D name $$anonymous$$pot, using a texture name texture$$anonymous$$potbrass. The name of the scirpt is Button and is attach in the GUItexture.
public class Button : $$anonymous$$onoBehaviour
{
// the material of the object you want to make transparent
public $$anonymous$$aterial object$$anonymous$$aterial;
private void OnGUI() {
 if( GUILayout.Button( "Touch" ) ) 
 { 
   var color = texture$$anonymous$$potbrass.color;
   if( color.a <= 0.5f ) 
     color.a = 1;
   else 
     color.a = 0.5f
   object$$anonymous$$aterial.color = color;
  }
 
                  }
errors
Assets/Button.js(1,21): BCE0043: Unexpected token: :.
Assets/Button.js(2,1): BCE0043: Unexpected token: {.
Assets/Button.js(5,10): BCE0043: Unexpected token: $$anonymous$$aterial.
Assets/Button.js(7,11): BCE0043: Unexpected token: void.
Assets/Button.js(9,5): BCE0043: Unexpected token: if.
Assets/Button.js(11,7): BCE0043: Unexpected token: var.
Assets/Button.js(11,10): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Button.js(14,7): BCE0044: expecting EOF, found 'else'.
this is a mixture of C# and javascript.. judging by you errors, you are using it as a js(?), so try this:
 // the material of the object you want to make transparent
 
 var object$$anonymous$$aterial :  $$anonymous$$aterial;
 
 function Start(){
 object$$anonymous$$aterial = GameObject.Find("texture$$anonymous$$potbrass").GetComponent(Renderer).material;
 }
 
 function OnGUI() {
 
 if(GUILayout.Button("Touch")){ 
 
   var color = object$$anonymous$$aterial.color;
 
   if( color.a <= 0.5f ) 
     color.a = 1;
   else 
     color.a = 0.5f
   object$$anonymous$$aterial.color = color;
  }
 }
 
                  (may I further suggest you take some time to learn the basics of scripting BEFORE you start trying to build a game.. You won't get far without understanding how this WOR$$anonymous$$S!)
Your answer
 
             Follow this Question
Related Questions
Why is my door opening and closing at the same time????????? 2 Answers
Platform moves when character steps on it 1 Answer
TouchPhase not firing correctly - Android 3 Answers
How to add Jump control from touch on screen? ANDROID 1 Answer
2D platformer controller script. How to jump with touch? 0 Answers