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 /
avatar image
1
Question by benjano · Nov 15, 2018 at 07:27 AM · camerascript.triggers

Trigger Camera Component (activate and deactivate)

Hi, I have a component in the main camera of the player that has the datamosh effect by Keijiro (https://github.com/keijiro/KinoDatamosh). What I'd like to have is that this component activates only when the player enters in specific areas (with a trigger I suppose) and then deactivates when exits. Is it possible? Thanks!

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
1
Best Answer

Answer by dan_wipf · Nov 15, 2018 at 07:49 AM

yes it is, if those zones have a collider setup as trigger.

then you can call in a script OnTriggerEnter() yourcomponent.enable = true; and on exit false.

you need to compare tag in this method. like if(other.tag == “Player”)


EDIT nr 2:

reedit of Code, explanation, and GitHub uploaded Example


 using System.Collections; 
 using UnityEngine;
 public class TriggerZoneMOSH : MonoBehaviour {
     public float Speed = 1;
     [Range(0,1)] public float MaxEntropy;
     Kino.Datamosh k_data;
     float t = 0;
     void Start(){
         k_data = Camera.main.GetComponent<Kino.Datamosh>();
         k_data.entropy = 0;
     }
     void OnTriggerEnter(Collider col){
         
         if(col.tag == "TriggerZone"){
             StopCoroutine("FadeOut");
             t = 0;
             k_data.Glitch();
             StartCoroutine("FadeIn");
         }
     }
     void OnTriggerExit(Collider col){
         if(col.tag == "TriggerZone"){
             StopCoroutine("FadeIn");
             t = 0;
             StartCoroutine("FadeOut");
         }
     }
     IEnumerator FadeIn(){
         while (true){
             t += Time.deltaTime;
             k_data.entropy = Mathf.SmoothStep(0,MaxEntropy,t / Speed);
             yield return new WaitForSeconds(0);
             if(k_data.entropy == MaxEntropy){
                 yield break;
             }
         }
     }
     IEnumerator FadeOut(){
         
         while (true){
             t += Time.deltaTime;
             k_data.entropy = Mathf.SmoothStep(MaxEntropy,0,t / Speed);
             yield return new WaitForSeconds(0);
             if(k_data.entropy == 0){
                 k_data.Reset();
                 yield break;
             }
         }
     }
 }
 

 



Attach this script to the Player. Be sure Datamosh is attached to the Main Camera. Now you create Triggerzones with a Collider (be sure to tick Is Trigger to enabled inside to Collider Property). You have to Tag the TriggerZone now to work with Script. Add a new Tag right under The Name of the GameObject (Dropdown Menu). There's the Option Add Tag.. hit that and give THIS NAME:

TriggerZone


If you choose Something else you have to edit the Script where it says if(col.tag == "TriggerZone") replace the "TriggerZone" with your name which you added above.


now you should be good to go. but you can have a look here at Github. I have uploaded a Demo Scene. with 3 TriggerZones and a simple Player Cube.

Comment
Add comment · Show 28 · 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 benjano · Nov 15, 2018 at 11:21 AM 0
Share

THAN$$anonymous$$S @dan_wipf ! but just to make things trickier... Is it possible to have the effect increase/decrease with a fade in/out when player enters/exits? Something like audio reverb zone.

avatar image dan_wipf benjano · Nov 15, 2018 at 01:54 PM 0
Share

yes, if the component has something like a dry/wet property

avatar image dan_wipf benjano · Nov 15, 2018 at 03:56 PM 0
Share

can you give me a photo of the inspector?(properties)

avatar image benjano dan_wipf · Nov 15, 2018 at 04:19 PM 0
Share

https://www.dropbox.com/s/361i7lsg3dmy5xr/Schermata%202018-11-15%20alle%2017.05.51.jpg?dl=0

https://www.dropbox.com/s/egvaendilbjjloi/Schermata%202018-11-15%20alle%2017.06.06.jpg?dl=0

avatar image benjano benjano · Nov 15, 2018 at 04:17 PM 0
Share

shoot, can't upoload images

Show more comments
avatar image benjano · Nov 15, 2018 at 11:10 PM 0
Share

WOW! Thanks my dude gonna try it in a few hours and get back here, thanks!

avatar image benjano · Nov 16, 2018 at 11:27 PM 0
Share

@dan_wipf sorry can't understand where to attach the fragment of the script...I thought was easier

avatar image dan_wipf benjano · Nov 17, 2018 at 04:50 AM 0
Share

put it on the trigger zone.

avatar image benjano dan_wipf · Nov 17, 2018 at 08:32 AM 0
Share

I'm attaching this: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class trigger : $$anonymous$$onoBehaviour {

 public float Speed = 1;

 void OnTriggerEnter(Collider col){
     if(col.tag == "Player"){
         StartCoroutine("FadeIn");
     }
 }
 void OnTriggerExit(Collider col){
     if(col.tag == "Player"){
         StartCoroutine("FadeOut");
     }
 }

 IEnumerator FadeIn(){
     while(true){
         Camera.main.GetComponent<$$anonymous$$ino.Datamosh>().enabled = true;
         GetComponent<$$anonymous$$ino.Datamosh>().entropy = $$anonymous$$athf.SmoothStep(0,1,Time.deltaTime * Speed);
         if(GetComponent<$$anonymous$$ino.Datamosh>().entropy == 1){
             yield break;
         }
     }
 }
 IEnumerator FadeOut(){
     while(true){
         Camera.main.GetComponent<$$anonymous$$ino.Datamosh>().entropy = $$anonymous$$athf.SmoothStep(1,0,Time.deltaTime * Speed);
         if(GetComponent<$$anonymous$$ino.Datamosh>().entropy == 0){
             GetComponent<$$anonymous$$ino.Datamosh>().enabled = false;
             yield break;
         }
     }
 }


and gives me a end-of-file error

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

163 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 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

Move camera forward/backwards with mouse wheel 1 Answer

How can I switch between two cameras ? 1 Answer

How can i make a FF Crystal Chronicles Ring of Fates Controller in Unity ? (Final fantasy) 0 Answers

Setting Virtual Camera by Script 0 Answers

How to make camera position relative to a specific target. 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