- Home /
How to use CollisionIgnoreManager.cs
Hi, I'm having problems using the CollisionIgnoreManager script. I want to start adding objects to the arrays but it's not working.
The code I'm using is this:
In CollisionIgnoreManager.cs I'm assuming the function I need is this one:
public void addIgnore( Collider newCollider ) {
addIgnore( newCollider, 0xffff, 0xffff );
}
And I'm trying to acces it from within a js with this:
CollisionIgnoreManager.addIgnore(collider);
However I get this message:
"BCE0020: An instance of type 'CollisionIgnoreManager' is required to access non static member 'addIgnore'."
I know that Javascripts are called before C# so I already moved the CollisionIgnoreManager.cs script to my Standard Assets folder.
Any ideas?
Answer by Ryan Scott · Oct 19, 2010 at 01:32 AM
Sorry I've been lax about checking answers. I am the author of CollisiognIgnoreManager.
You need to add this script to some component in your scene (it doesn't matter which or where that game object is, it just needs to be added). This class is setup to operate as a Singleton, such that the class itself stores a reference to the instance. As such you should only add a single CollisionIgnoreManager script to your scene (i.e. don't put it on multiple objects or anything like that).
Once it is in your scene access it like so: CollisionIgnoreManager.getInstance().AddIgnore( whatever );
I haven't revisited that code in some time, and certainly it can be cleaned up, but that is how you would use the version that is on the wiki currently.
Answer by Peter G · Sep 12, 2010 at 07:29 PM
Your error means that you have to get a reference to an instance of CollisionIgnoreManager. I don't know how that script works though, so it either wants the script attached to an object.
//Probably this one.
//______________________________________________
var collisionController : CollisionIgnoreManager = SomeGameObject.GetComponent(CollisionIgnoreManager);
collisionController.AddIgnore(collider);
//______________________________________________
or, if that is not how the script is setup then you just have to make a new instance in your script.
collisionController = new CollisionIgnoreManager();
collisionController.AddIgnore(collider);
My best advice would be to wait until Unity 3 comes out with layer based collisions unless you need your game to be released in the next month or so (there is no public date for the release. Just summer 2010.)
The first approach is not returning any errors... but the script is not working. Evidently I'm doing something (very) wrong.
The script I'm trying to use is this (in case anyone wants to take a look):
http://www.unifycommunity.com/wiki/index.php?title=CollisionIgnore$$anonymous$$anager
It's supposed to avoid collisions in groups rather that in single objects. I'll make some more tests.
Thanx Peter G :)