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 /
avatar image
0
Question by Benjeta · Jul 15, 2014 at 12:51 AM · shaderdestroy

Dissolve object on Gameobject Destory

Hi, I've the dissolve>Diffuse shader from the Wiki by genericuser :|.

How to make a gameobject with a lot of function in his script dissolve when he destroy him or when the dialogue has finished playing ? How to automate the slice amount cursor from 0 to 100 in 2 seconds and then destroy the object ?

Thanks by advance.

Here the script :

    #pragma strict
  
 var CC : GameObject;
 var CCBad : GameObject;
  public var pop : AudioClip;
  public var pop2 : AudioClip;
  public var dialogue : AudioClip;
  
 function OnTriggerEnter (other : Collider) {
 if (other.tag == "Player"){
 CC.SetActive(true);
 CCBad.SetActive (false);
  AudioSource.PlayClipAtPoint(pop, transform.position );
  AudioSource.PlayClipAtPoint(dialogue, transform.position );
 }
 }
  
 function OnTriggerExit (other : Collider) {
 if (other.tag == "Player"){
 CC.SetActive(false);
 CCBad.SetActive (true);
 Destroy( this.gameObject );
 AudioSource.PlayClipAtPoint(pop2, transform.position );
 }
 }
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 sethuraj · Jul 17, 2014 at 06:41 AM

If I understood you correctly,my suggestion is that you can use a co-routine to do this.Loop until a value which is initially 100 gets reduced to zero and simoultaneously assign the value to the shader,Once the value reaches zero,exit the loop and perform post dissolve task like destroying the game object.

Here is the example code (not tested).Sorry my code is in C#

 //The slice value to be assigned to the shader
 float Val_Slice=100;    
 
 void OnTriggerEnter (Collider other) 
 {
   if (other.gameObject.tag == "Player")
   {
     CC.SetActive(true);
     CCBad.SetActive (false);
     AudioSource.PlayClipAtPoint(pop, transform.position );
     AudioSource.PlayClipAtPoint(dialogue, transform.position );
   }
 }
 
 void OnTriggerEnter(Collider other)
 {
   if(other.gameObject.Tag=="Player")
   {
     //Start the FadeAndDestroy coroutine here
     StartCoroutine("FadeAndDestroy");
   }
 }
 
 IEnumerator FadeAndDestroy()
 {
   //Loop until slice value reaches zero
   while(Val_Slice>0.0f)
   {
     //Reduce slice value over time
     Val_Slice-=Time.deltatime;
 
     //Apply the slice value to shader(change the string "_SliceAmount" to ur shader property string)
     renderer.material.SetFloat("_SliceAmount",Val_Slice);
 
     //Use this line if you want to increase the delay in decrementing
     //yield return new WaitForSeconds(0.1f);
 
   }
 
   //Loop exited since value reached zero (perform post dissolve task here)
   CC.SetActive(false);
   CCBad.SetActive(true);
   Destroy(this.gameObject);
   AudioSource.PlayClipAtPoint(pop2,transform.position);
 }

}

Good Luck...

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 Benjeta · Jul 17, 2014 at 11:48 AM 0
Share

Thanks :) But when I put some public variable public GameObject CC ; public GameObject CCBad ;

For the functions, the script not show them on the inspector :/

I'll investigate this and validate your answer once i'm sure the script work ;) Thanks for your reply ! EDIT : No, I don't get it

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

23 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

Related Questions

Two objects are placed at the same place. How to destroy one and keep another? 1 Answer

Jelly Shader 1 Answer

Destroy object when hit by other object 1 Answer

Destroying and recreating renderers/shaders at runtime 1 Answer

Blending one material/texture/shader to another 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