I have an object which, upon meeting certain conditions, will “disappear” as far as the player can tell, and later reappear. Getting it to not be visible is easy. However, the player is capable of standing on said object when it is visible. Thus, this object has a collision. (It also has a rigidbody because it moves.) So in addition to making the object invisible, I need the object to stop colliding with the player. (Or really any object at all.)
I am having difficulty making the object stop colliding with the player.
I thought I could simply disable it, like “myCollison.enabled = false;”. But I run into two errors.
First of all, I have the error “Type UnityEngine.Collision2D' does not contain a definition for
enabled’ and no extension method enabled' of type
UnityEngine.Collision2D’ could be found” which means I can’t simply disable the collsion with that flag.
Secondly, I am not properly getting the collision to use as a variable within my script. I tried “myCol = GetComponent();” but I get the error “The type UnityEngine.Collision2D' must be convertible to
UnityEngine.Component’ in order to use it as parameter T' in the generic type or method
UnityEngine.Component.GetComponent()'” so I’m going about that the wrong way too.
So I have two questions.
-
How do I disable (and re-enable) the collision of an object so it can collide and not collide at a whim?
-
How do I access an object’s own collision in the script?