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 ltackett · May 04, 2015 at 12:12 PM · scripting problemcollisioncamera followgame object

How do I disable 2D camera follow when my player collides with a trigger object?

New to Unity. New to C#. Not new to programming. I have an idea about what I'm doing wrong, but I haven't found an answer on the forums that works for my particular case.

I need a script that I can add to an invisible object. When my player collides with the object, the script should disable the Camera2DFollow component in the target camera.

Here's the error I'm getting:

The type or namespace name `Camera2DFollow' could not be found. Are you missing a using directive or an assembly reference?

Here's my script:

 using UnityEngine;
 using System.Collections;
 
 public class ToggleCameraFollow : MonoBehaviour {
 
     public UnityEngine.Camera Camera;
 
     void OnTriggerEnter (Collider other) {
         Camera.GetComponent<Camera2DFollow>().enabled = false;
     }
     
     void OnTriggerExit  (Collider other) {
         Camera.GetComponent<Camera2DFollow>().enabled = true;
     }
 }
Comment
Add comment · Show 3
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 sethuraj · May 04, 2015 at 12:11 PM 1
Share

hi it seems a na$$anonymous$$g problem.A class named 'Camera' with capital C is aleready declared by unity under UnityEngine.Camera.But the object name u gave is same as the class name 'Camera' with capital C.

Use a different object name like this

 public UnityEngine.Camera $$anonymous$$yCamera;

And make sure you drag and drop the camera object to $$anonymous$$yCamera field in the ispector

or If you have only one camera with $$anonymous$$ainCamera Tag,you can use something like this

 Camera.main.GetComponent().enabled = BoolValue;

Hope this helps

avatar image ltackett · May 04, 2015 at 12:37 PM 0
Share

@sethuraj thanks!

I discovered the problem with using the name Camera on accident just a few hours ago. Good advise, and the way you explained it makes sense.

I also discovered that I was targeting the wrong script (Camera2DFollow is namespaced under the 2D standard assets), and I was using the wrong collider for my events (was using Box Collider 2D, which fires OnTriggerEnter2D, etc.).

Here's what worked on a sprite object with Box Collider 2D as a trigger:

 using UnityEngine;
 using System.Collections;
 
 public class ToggleCameraFollow : $$anonymous$$onoBehaviour {
 
     public  UnityEngine.Camera camera;
 
     private UnityStandardAssets._2D.Camera2DFollow followCamera;
 
     void Awake () {
         followCamera = camera.GetComponent<UnityStandardAssets._2D.Camera2DFollow>();
     }
 
     void OnTriggerEnter2D (Collider2D other) {
         Debug.Log("Stop Following Player");
         followCamera.enabled = false;
     }
     
     void OnTriggerExit2D  (Collider2D other) {
         Debug.Log("Resume Following Player");
         followCamera.enabled = true;
     }
 }
 
avatar image sethuraj · May 04, 2015 at 12:41 PM 0
Share

@ltackett Good Luck

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

SetActive messes up everything? 1 Answer

How to count from 2nd collision 1 Answer

OnCollisionEnter getting called more than once,OnCollisionEnter called more than once 1 Answer

How can you make an object visible in Unity when you jump on it? 0 Answers

Can someone help me with calling a method from another Game Object? 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