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 cronkie · Aug 18, 2012 at 07:45 PM · cameraontriggerenter

Alternating Two Settings with One OnTriggerEnter Collider

Hey all - I have a quick question.

I am doing some tests with switching fixed cameras with OnTriggerEnter. I am using a 3rd person point and click paradigm and am successfully switching the main camera/audio listener to a second main camera/audio listener when the 3rd person avatar hits the trigger.

My question is how would I switch BACK to the previous main camera/audio listener setting when I go through the same OnTriggerEnter collider again? Ultimately, I want to be able to alternate between two fixed camera settings infinitely based off of one OnTriggerEnter collider. Think Point & Click Adventure or "Resident Evil 1" style.

Here's the simple part that I scrounged together:

 //This will switch your main camera (and audio listener) when you hit a trigger
 //Make sure you have your second camera inactive when the scene starts
 
 var camera1 : Camera;
 var camera2 : Camera;
 
 private var startCamera : int = 1;
 
 function OnTriggerEnter(other : Collider)
 {
    if(other.CompareTag("Player"))
    {
       
       camera1.enabled = false;
       camera1.gameObject.active = false;
       camera2.enabled = true;
       camera2.gameObject.active = true;
       startCamera = 2;
       
    }
 
 }

Thanks a bunch!

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

Answer by ScroodgeM · Aug 18, 2012 at 07:47 PM

camera1.enabled = !camera1.enabled;
camera1.gameObject.active = !camera1.gameObject.active;
camera2.enabled = !camera2.enabled;
camera2.gameObject.active = !camera2.gameObject.active;
startCamera = startCamera == 2 ? 1 : 2;
Comment
Add comment · Show 3 · 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 cronkie · Aug 18, 2012 at 08:19 PM 0
Share

Seems like that almost works. It does turn off the 1st Camera/Audio Listener and tries to switch over to the other, but it actually turns off the camera component of the 2nd Camera. The Audio Listener and everything else seems to change over correctly. You can hear from the 2nd perspective but everything renders in black.

avatar image ScroodgeM · Aug 18, 2012 at 09:16 PM 0
Share

hmm... note that by default camera2 component should be off and camera1 on. my code example just changes state to inversed every time. if both cameras are enabled, on code executing both will be disabled.

avatar image cronkie · Aug 19, 2012 at 05:04 AM 0
Share

Ah yes. I'm an idiot. I was thinking that if I had the maincamera disabled, it would make the camera component behave accordingly. I WAS WRONG!

This worked, thanks a lot, Scroodge. $$anonymous$$uch appreciated.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Camera does not trigger OnTriggerEnter-event 1 Answer

2d Platformer Tutorial moving the camera via script and disabling player controls when entering a trigger 1 Answer

Switching Camera on Collision won't work 0 Answers

triggering visibility with camera path 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