How to stop a moving game object as soon as it collides with another game object?
<p>I have a ring as game object which I move on the y axis up and down with the keyboard keys. </p>

<p>As information: Both game objects have a rigidbody attached as well as a collider. </p>

<p>Here some code: </p>

<pre><code>// get key up and the ring will move upwards
    if (Input.GetKey (KeyCode.UpArrow)&amp;&amp;(shouldMove))
    {
        transform.position += Vector3.up * speed * Time.deltaTime;
    }

    // get key down and the ring will move downwards
    if (Input.GetKey (KeyCode.DownArrow))
    {
        transform.position += Vector3.down * speed * Time.deltaTime;
    }
</code></pre>

<p>Now I would like do disable the movement of this ring as soon as it hits another game object. I tried the the OnCollisionEnter function which gives me the information that I hit an object (using debug.log) however I can continue move it and pushing the game object which was hidden... </p>

<pre><code>void OnCollisionEnter(Collision collision) {


    if (collision.gameObject.name == "Sphere") {            
        Debug.Log ("Hit Sphere");

    }

}
</code></pre>