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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by gringofxs · Nov 15, 2012 at 08:54 PM · touch

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.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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;
 
      }
 
 }
Comment
Add comment · Show 7 · 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 gringofxs · Nov 15, 2012 at 09:51 PM 0
Share

my object name is $$anonymous$$pot, where do i specified this?

avatar image gringofxs · Nov 15, 2012 at 09:53 PM 0
Share

is a 3d model

avatar image silethunde · Nov 15, 2012 at 10:02 PM 0
Share

Just pass the object's material as a reference to this script

avatar image gringofxs · Nov 15, 2012 at 10:49 PM 0
Share

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'.

avatar image Seth-Bergman · Nov 15, 2012 at 11:12 PM 0
Share

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!)

Show more comments

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

12 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

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


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