- Home /
This post has been wikified, any user with enough reputation can edit it.
Raycast: OnCollisionStay() detect collision not on Ray but Object?
How can I detect if an Object is hit by a ray-cast a certain amount of time on itself.
This is the code I use to check for collision with objects which I need to enable also for Rays!
`void OnCollisionStay(){
elapsedTime = Time.time - startTime;
if (name == "WrongButtonHover(Clone)" && elapsedTime > activationTime){
startTime = Time.time;
MainCamera.GetComponent<ButtonSpawner>().wrongButton();
}`
I tried to use:
void FixedUpdate() { if ( GetComponent().velocity.magnitude > 0.01 ) { Debug.Log("does not work if rigid-body has fixed position!");}
Comment
Answer by Umresh · May 12, 2015 at 01:32 PM
This will check for the collision with the ray
if( Physics.Raycast(transform.position,Vector3.forward,"DistanceToDetectRaycast") )
{
//Check for the time of stay . Then Do something
}
Your answer
Follow this Question
Related Questions
Raycast from inside an object 2 Answers
Raycast doesn't register Rigidbody 1 Answer
Detecting collisions with raycast or not? 1 Answer
Someone can help with Ray/Collide? 1 Answer
Collider Vision AI question. Solved! 0 Answers