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 /
  • Help Room /
avatar image
1
Question by benjano · Nov 17, 2018 at 09:23 PM · script.controllerinputs

How to Activate/Deactivate Component via Inputs

Hi guys, I need to Activate and Deactivate a component (an external script) that is attached to player's camera via gamepad input. Basically it's a glitch effect that I need to activate with one button (ex. L2) and deactivate with another button (ex. R2) Can't find any (noob) method...

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dan_wipf · Nov 18, 2018 at 08:04 AM

Depends which controller you have. There are some Schematics over the Internet so you could do something like this below. (X-BoxOne, PS4)

What @Twistyd explained was the Method to a UI Button not a GamePad button/input.


     bool m_Switch;
     Kino.Datamosh k_data;

     void Update () {
         k_data = Camera.main.GetComponent<Kino.Datamosh>();
 
 
         //there are schematics of GamePad Layouts in the web. 
         //Left back button(L1) for xboxOne / ps4 i believe 
         if(Input.GetKeyDown(KeyCode.JoystickButton4)){
             Camera.main.GetComponent<Kino.Datamosh>().enabled = true;
         }
         //right back button(R1) for xboxOne / ps4
         if(Input.GetKeyDown(KeyCode.JoystickButton5)){
             Camera.main.GetComponent<Kino.Datamosh>().enabled = false;
         }
 
 
 
         // if a single button should enable/disable component
         if(Input.GetKeyDown(KeyCode.JoystickButton4)){
             m_Switch = !m_Switch;
         }
         if(m_Switch){
             k_data.enabled = true;
         }
         if(!m_Switch){
             k_data.enabled = false;
         }
     }


Comment
Add comment · Show 8 · 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 18, 2018 at 08:33 AM 0
Share

this inside the datamosh script?

avatar image dan_wipf · Nov 18, 2018 at 09:54 AM 0
Share

no just put this in an new script, and add it to the player, well basicly it doesnt matter where you’d put this

avatar image benjano dan_wipf · Nov 18, 2018 at 10:27 AM 0
Share

sorry dan, I'm very bad at it. wrote this: using System.Collections; using System.Collections.Generic; using UnityEngine;

bool m_Switch; $$anonymous$$ino.Datamosh k_data; void Update () { k_data = Camera.main.GetComponent<$$anonymous$$ino.Datamosh>();

 //there are schematics of GamePad Layouts in the web. 
 //Left back button(L1) for xboxOne / ps4 i believe 
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.JoystickButton4)){
     Camera.main.GetComponent<$$anonymous$$ino.Datamosh>().enabled = true;
 }
 //right back button(R1) for xboxOne / ps4
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.JoystickButton5)){
     Camera.main.GetComponent<$$anonymous$$ino.Datamosh>().enabled = false;
 }



 // if a single button should enable/disable component
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.JoystickButton4)){
     m_Switch = !m_Switch;
 }
 if(m_Switch){
     k_data.enabled = true;
 }
 if(!m_Switch){
     k_data.enabled = false;
 }

}

It gives me this error: Assets/scripts/NewBehaviourScript.cs(6,0): error CS1525: Unexpected symbol `$$anonymous$$ino'

avatar image dan_wipf benjano · Nov 18, 2018 at 12:16 PM 1
Share

ok if you create a new script

then put my code after: yourscriptname : monobehaviour {

delet all inside the brakets of the new script{} and add there the code

avatar image Twistyd · Nov 18, 2018 at 10:21 AM 0
Share

@dan_wipf is right, I gave a UI button answer, my bad, sorry, was late and I misread lol. Hope you get your issue sorted.

avatar image benjano Twistyd · Nov 18, 2018 at 10:28 AM 0
Share

no, you guys are great! thanks both

avatar image benjano · Nov 18, 2018 at 01:43 PM 0
Share

dude. works. perfectly. neat. crying loud, you saved me. many thanks guys! the effect is cool, thinking to implement with your fading effect for much coolness.

avatar image dan_wipf benjano · Nov 18, 2018 at 01:56 PM 0
Share

just leave a like and accept answer :-)

avatar image
0

Answer by Twistyd · Nov 17, 2018 at 10:18 PM

Few ways you could do it.

You could write 2 public functions which handle the activation and deactivation of the effect.

Something like:

     public GameObject effectThing;     // Your effect object.
     
     public void Activation(){
         effectThing.SetActive(true);
     }
     
     public void Dectivation(){
         effectThing.SetActive(false);
     }    

Then back in Unity drag whichever object contains the functions in the script above in to your buttons onClick

alt text


Or you could directly drag in the effectThing GameObject to the onClick and then in the bit that says no function select GameObject and then SetActive (bool)

alt text

I too am fairly nooby so there may be better ways to do it.


screenshot-4.jpg (28.6 kB)
screenshot-5.jpg (42.1 kB)
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 benjano · Nov 17, 2018 at 10:34 PM 0
Share

thanks for you quick reply! I don't understand with this method (I didn't know it) how I set Up a custom $$anonymous$$ey for the action. The effect that I need to control it's on my main camera, so this is what I've done:

Created a Game Object and put there the button script then assign on OnClick my main camera and in function I can see my effect (datamosh) with all the settings! but I don't understand where I have to assign buttons to settings! Thanks!

avatar image
0

Answer by benjano · Nov 18, 2018 at 06:45 PM

Unfortunately I've tried to make a Build, everything works fine but the Datamosh effect, when I press L1 the camera freezes on a frame until I press it again. basically just stops the frame and no datamosh effect applied!

Seeing the debug in the build while pressing the button to activate the datamosh component it gives me this error: NullReferenceException: Object reference not set to instance of an object

It dosn't pop up in unity in the game mode!

Comment
Add comment · Show 20 · 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 dan_wipf · Nov 18, 2018 at 07:07 PM 0
Share

post a photo of the debug, if possible ir the whole debug log

avatar image benjano dan_wipf · Nov 18, 2018 at 07:13 PM 0
Share

it's just infinite lines of this: (Filename: /Users/Ben/Dropbox/mesh_depression/Assets/$$anonymous$$ino/Datamosh/Datamosh.cs Line: 161)

NullReferenceException: Object reference not set to an instance of an object at $$anonymous$$ino.Datamosh.OnRenderImage (UnityEngine.RenderTexture source, UnityEngine.RenderTexture destination) [0x00013] in /Users/Ben/Dropbox/mesh_depression/Assets/$$anonymous$$ino/Datamosh/Datamosh.cs:161

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

@dan_wipf did you find out?

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

168 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Spaceship Script not working? 0 Answers

My character doesn't detect collisions or Hinge joint. 0 Answers

REALLY NEED HELP How do I get a gun to fire when i press R2 on the ps4 controller? 0 Answers

my wireless switch Gamecube controller is read as a "Lic Pro Controller" how do I fix it 0 Answers

I need help making a 2 player car game 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