- Home /
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;
}
}
}
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
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.
Thanks Nick4 for the fast reply,
Although I have no "errors". I'm still not getting anything even messages in console
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
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
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!
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.
Your answer