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 Bentoon · Aug 16, 2014 at 08:04 PM · c#camerabooleanvisible

camera collision visibility (c#)

Hello people

Simple question my Camera is moving along a path ...

and when it hits an invisible plane, I want it to trigger the visibility of other planes I identify in the inspector (P1, P2 etc) Ideally I would like to use a bool so that I can trigger it off later... What's wrong with my logic? Thanks

 using UnityEngine;
 using System.Collections;
 
 public class tagVisible : MonoBehaviour {
 
      public GameObject P1;
     public GameObject P2;
     public GameObject P3;
 
     bool showMe = false;
     
     // Use this for initialization
     void Start () {
         //GameObject[] f1 = GameObject.FindGameObjectsWithTag("city"); 
         P1.GetComponent<MeshRenderer>().enabled = false;
         P2.GetComponent<MeshRenderer>().enabled = false;
         P3.GetComponent<MeshRenderer>().enabled = false;
     }
 
 
 
     void OnCollision (Camera) {
         Debug.Log("hit");
 
             if(showMe = false) {
             showMe = true;
         }
 
         if(showMe = true) {
             P1.GetComponent<MeshRenderer>().enabled = true;
             P2.GetComponent<MeshRenderer>().enabled = true;
             P3.GetComponent<MeshRenderer>().enabled = true;
             
         }
 
 
     }
 
 }
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

2 Replies

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

Answer by Bentoon · Aug 17, 2014 at 05:11 PM

Nick Everything worked after I changed it from onCollisionEnter(Collider coll)

to OnTriggerEnter(Collider other)

Thanks so much for your persistence and help

Comment
Add comment · 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
0

Answer by Nick4 · Aug 16, 2014 at 08:09 PM

It's not OnCollision, it's OnCollisionEnter.

 void OnCollisionEnter(Collision col)
 {
     Debug.Log("hit");
  
     if(showMe = false) {
         showMe = true;
     }
  
     if(showMe = true) {
         P1.GetComponent<MeshRenderer>().enabled = true;
         P2.GetComponent<MeshRenderer>().enabled = true;
         P3.GetComponent<MeshRenderer>().enabled = true;
  
     }
 }

And as you can see it doesn't send a Camera parameter but Collision instead.

Comment
Add comment · Show 12 · 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 Bentoon · Aug 16, 2014 at 08:16 PM 0
Share

Thanks Nick4 for the fast reply,

Although I have no "errors". I'm still not getting anything even messages in console

avatar image Nick4 · Aug 16, 2014 at 08:21 PM 0
Share

Does the your camera have a collider too? and its isTrigger variable is turned off? Also don't forget that at least one of the colliding objects must have a rigidbody, does your camera or planes have rigidbody attached? $$anonymous$$ake sure those are all checked then test it again

avatar image Bentoon · Aug 16, 2014 at 08:23 PM 0
Share

just to make sure : I am attaching this script to the Trigger Plane (which has a collider and is set to "trigger") and the Camera is indeed hitting it but I have no console message. I even restarted

avatar image Bentoon · Aug 16, 2014 at 08:40 PM 0
Share

Thanks Nic, everything has a collider / plane has a rigidbody too. but if I don't check "isTrigger" on plane, I get the following error message :

Actor::update$$anonymous$$assFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!

avatar image Nick4 · Aug 16, 2014 at 08:47 PM 0
Share

FYI Planes can't have rigidbodies or you'll get that error, make sure only your camera has rigidbody and your collision will be detected.

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

UNITY 3D: How to make the camera follow the player? Smoothly 2 Answers

How can I limit the rotation on the Y axis so the player cant spin the camera 360 in an FPS game? 0 Answers

Make Prefab Look At Target 2 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