- Home /
how turn off the mesh collider?
Hi to all...
how turn off the mesh collider? in JAVASCRIPT please
thanks in advance
It really would not have been a crime to ask two questions in one with http://answers.unity3d.com/questions/30811/how-turn-off-the-mesh-renderer. Since their similarity is so amazing.
@Proclyon: Actually, they're quite different. Disabling a renderer is easy, whereas disabling a collider is actually a pain.
hah funny, well word count really says just as much as letter similarity in semantics I guess. Thanks for the heads up. Still feels wrong though seeing 2 questions look that much alike piled up.
Answer by skovacs1 · Dec 08, 2010 at 03:36 PM
You can't really "turn off" a Collider.
You can them at run-time with Destroy(collider).
You can get the physics engine to ignore collisions with the collider or not, using Physics.IgnoreCollision or Physics.IgnoreLayerCollision.
You can replace the collider with a different collider and perhaps this may serve your purpose.
If you instantiated the object from a prefab without a collider, you could add the collider when you need it and replace the object with the original prefab to remove the collider, copying over whatever settings, positioning, etc. is relevant.
Specifically for MeshColliders, you can specify a mesh to use. By assigning it an empty mesh, it should effectively be disabled. You can then re-enable it by assigning it to be something like GetComponent(MeshFilter).mesh
.
Right, somehow I missed that, having only ever called Destroy(gameObject) or the like. Thanks Eric5h5. Oversight corrected.
Answer by Linus · Apr 07, 2013 at 06:39 PM
I think that the current answer is outdated.
You can disable a collider at runtime:
http://docs.unity3d.com/Documentation/ScriptReference/Collider-enabled.html
This will disable colliders on objects that have the tag MoveGuide
for (var obj : GameObject in GameObject.FindGameObjectsWithTag("MoveGuide")){
obj.gameObject.collider.enabled = false;
}
Answer by danny0_89 · Mar 01, 2017 at 07:24 AM
I use this scrip when the object collides with "Player" it dissapear after 3f and reaperr after 2f
//Created by Danny0
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class touchdisapear : MonoBehaviour
{
public Renderer rend;
public MeshCollider rend2;
void Start()
{
rend = GetComponent<Renderer>();
rend2 = GetComponent<MeshCollider>();
rend.enabled = true;
rend2.enabled = true;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player")
{
StartCoroutine(Time());
}
}
// Update is called once per frame
void Update()
{
}
IEnumerator Time()
{
yield return new WaitForSeconds(3f);
rend.enabled = false;
rend2.enabled = false;
yield return new WaitForSeconds(5f);
rend.enabled = true;
rend2.enabled = true;
}
}
Necro, pay attention to the dates. This was answered years ago. And you're doing it in a completely dumb way.
For one he wanted it in UnityScript not C#. For two - why make things more complicated than it needs to be?
You could have easily just said for C#
void Start(){
GetComponent<Collider>().enabled = false;
}
Answer by teameden · Jul 26, 2011 at 08:38 AM
gameObject.collider.convex = false;
Is working nice for me, hope that helps.
-TE
Answer by toddisarockstar · Feb 17, 2015 at 03:37 AM
you can simply get rid of it all together with:
Destroy(gameObject.collider);
Your answer
![](https://koobas.hobune.stream/wayback/20220613090242im_/https://answers.unity.com/themes/thub/images/avi.jpg)