- Home /
Question by
vladtheimpaled7 · Jun 29, 2014 at 02:54 PM ·
c#collisiononcollisionstay
How do I use OnCollisionStay?
I wrote this code and it doesn't seem to work when the ball collides with the robot
using UnityEngine;
using System.Collections;
public class shooting : MonoBehaviour {
//Use this for initialization
void Start () {
}
// Update is called once per frame
public void OnCollisionStay(Collision collision) {
if (collision.gameObject.name == ("blue robot")) {
Debug.Log ("chip");
//if (Input.GetKey (KeyCode.Space))
//rigidbody.AddForce (Vector3.right * 1000);
//if (Input.GetKey (KeyCode.Space))
//rigidbody.AddForce (Vector3.up * 700);
}
}
}
Comment
Answer by Jeff-Kesselman · Jun 29, 2014 at 02:57 PM
Get rid of the public, thats wrong.
In general you must always match the way the Unity examples show you a callback is declared exactly in order for it to work.
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionStay.html
Answer by himanshugupta159 · Jul 03, 2019 at 05:46 AM
Hi i have written a blog on -How colliders work in unity and how to interact with colliders using script. Pls visit and show some love. Thank you