• 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
0
Question by chucky831 · Jun 09, 2013 at 09:45 AM · androidcameraalphamainzombies

room darkens

how can I do so that if an enemy comes against the room darkens slowly? I thought of a trigger and create a transparent plane. This is my code but it does not work. Tips?

 #pragma strict
 
 
 //Ogni volta che uno zombie collide con il protagonista per 1 secondo aumenta l'opacità
 // della texture che simula il sangue. Al terzo contatto riparte il livello.
 
 
 //script da applicare al protagonista
 
 
      var pianoTexture : GameObject;
 
 
 function Start () {
 
 pianoTexture = GameObject.FindGameObjectWithTag("pianoTexture");
 
 pianoTexture.renderer.material.color.a =0;
 
 
 
 
 }
 
 function Update () {
 
 }
 
 
 function OnTriggerEnter(pippo:Collider){
 
 
 
    if(pippo.tag == "Finish"){
    print("COLLISIONE OK");
 
           /*   var tempo = 0;
              var max = 1.0;
              
              
              if(tempo>max)  { //0 > 1
              
                pianoTexture.renderer.material.color.a += 255.0;
                
                tempo = 0;
              
              
              
              }else{
              
              
              tempo += Time.deltaTime;
              
              
              }
              
              
              
 */
 }
 
 
 }
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 xandermacleod · Jun 09, 2013 at 09:56 AM

Depending on your platform choice, I wouldn't recommend a semi-transparent image infront of the camera as that will up your drawcalls significantly - a better solution would be to dim the lights illuminating your scene.

However, if for some reason you don't want to do that - here is a handy fader script that can be used to fade the material of a given object over a period of time.

(Remember that because this is an IEnumerator you will want to call it using Unity's StartCoRoutine function. You will also need to be careful at some point later on in your script to stop the coroutine, otherwise you will have multiple unnecessary threads). For more information on using StartCoRoutine I'd recommend just searching for it on unity answers.

 IEnumerator AlphaFadeTo(GameObject ObjectToFade, float FinalAlphaValue, float TotalFadeTime)
     {
         float alpha = transform.renderer.material.color.a;
         Color newColor = Color.white;
         for (float t = 0.0f; t <= 1.0f; t += Time.deltaTime / TotalFadeTime)
         {
             newColor = new Color(1, 1, 1, Mathf.Lerp(alpha,FinalAlphaValue,t));
             ObjectToFade.renderer.material.color = newColor;
             yield return null;
         }
         newColor.a = FinalAlphaValue;
         ObjectToFade.renderer.material.color = newColor;
     }
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Possible to use an external camera (USB) while running on Android? 1 Answer

Dragging Camera based on Touch 0 Answers

Android: Game not fitting on screen 1 Answer

Camera Size on Android 0 Answers

GUIText Alpha transparency not working on Android Table? 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