How to set a BoxCollider to a variable, and disable it?
I'm stuck on something which I thought would be simple. I need to disable the BoxCollider on my projectile when it hits something. I don't want to delete it straight away, because it has a particle trail which needs to finish, so I thought hiding the graphic and disabling the BoxCollider would do the trick.
This doesn't work, but I thought it would:
private var collider : BoxCollider;
function Start () {
collider = GetComponent.<BoxCollider>();
}
function OnTriggerEnter(other: Collider) {
collider.isActive(false);
}
I get the error "Language feature not implemented: Ambiguous(BulletScript.collider, UnityEngine.Component.Collider) I definitely have a Box Collider on the object this script is on. Any ideas guys?
@daviddickball Try using .enabled = false; ins$$anonymous$$d of .isActive(false);
Answer by SneakySquid · Jan 17, 2016 at 11:29 AM
It seems like it is confusing the name "collider" with something else. I'd suggest changing the name. Also you should use enabled = false
instead of isActive
for a component.
private var boxCollider : BoxCollider;
function Start () {
boxCollider = GetComponent.<BoxCollider>();
}
function OnTriggerEnter(other: Collider) {
boxCollider.enabled = false;
}
Thanks for the tip about using enabled = false, but your code above doesn't change anything. All you've done is change the variable name?
That's correct, but as I said, I think the name you've chosen is being confused by another class or component in Unity. I added your code to my own project and I got the same errors as you. When I changed the name, it was fine.
Yes, $$anonymous$$onoBehaviours already has some variables like "collider", "collider2d", "renderer" and other ones that used to have the same funcionality as the "transform" variable (picking the component faster than GetComponent.()", but they became deprecated, so you can't use then now. They still exist, but only to maintain compatibility with older projects.
Your answer
Follow this Question
Related Questions
Semicolon expected before end of line 0 Answers
Javascript Help 0 Answers
Trigger enabling component works in one statement but not another? 1 Answer
Can't find any Unityscript tutorials 3 Answers
UnityScript to C# Conversion 1 Answer