Quantcast
Viewing latest article 6
Browse Latest Browse All 90

Answer by Kleptomaniac

Have you tried enabling your Box Collider and Rigidbody when escape is first pressed and then disabling when pressed again? Since enabling and disabling these two components is not possible there are two possible workarounds you could try. The first involves disabling your collider and setting your rigidbody to kinematic (therefore making it not driven by the physics engine). While this would be the most efficient way to do it, I'm not sure if it will actually work. If it does, I would do it like this: private var esc : boolean = false; private var rigid : Rigidbody; private var coll : BoxCollider; function Start () { rigid = GetComponent(Rigidbody); coll = GetComponent(BoxCollider); rigid.isKinematic = true; coll.enabled = false; } function Update () { if (Input.GetKeyDown(KeyCode.Escape)) { if (!esc) { rigid.isKinematic = false; coll.enabled = true; esc = true; } else { rigid.isKinematic = true; coll.enabled = false; } } } If that doesn't work however, I would try destroying the rigidbody component and then using AddComponent every time you enter your escaped state. This won't be very efficient, however it's the only alternative I can think of. Hope that helps, Klep

Viewing latest article 6
Browse Latest Browse All 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>