- Home /
detecting rigidbody collsion with no extra script
Hello All.
I am interested into accessing collision status of rigidbody with no extra script attached onto it, and which is not working with event.
I am currently having something theorically like this
public class MyClass: MonoBehaviour {
Rigidbody PositionReferenceA;
Rigidbody PositionReferenceB;
void Start () {
PositionReferenceA = (Rigidbody)(new GameObject()).AddComponent("Rigidbody ");
PositionReferenceB = (Rigidbody)(new GameObject()).AddComponent("Rigidbody ");
}
}
And I would like to have something like this in my class :
void Update() {
if(PositionReferenceA.IscurrentlyColliding()==true)
//do stuff here
}
Is there anyway to do this? I don't see any accesser like this for the rigidbody class, but maybe there is a tricky way to do this?
Thanks for your time.
To myself, and anyone confronted to the same problematic : It is necessary to have a counter of collision, as there could be multiple collision, for example :
void OnTriggerEnter(Collider collidingObject) {
Debug.Log (this.name+" object has collision with " +collidingObject.gameObject.name);
CollisionQtty++;
}
void OnTriggerExit(Collider collidingObject) {
Debug.Log (this.name+" object lost collision with " +collidingObject.gameObject.name);
CollisionQtty--;
}
In this case, it is just necessary to test if CollisionQtty is equal to 0.
Answer by Benproductions1 · Jun 07, 2013 at 12:25 AM
Hello,
Other than writing your own rigidbody classe, there is no possible way of achieving what you want. You will need to attach a script to it, in order to test for colisions :)
Hope this helps,
Benproductions1
Okay, I will try by using my own class so.
Thanks for the help by the way.