how to stop my cube when touch collider??

when touch collider then stop my cube…

Hi,

You didn’t mentioned much details regarding your cube, but I assume it is rotating.
I hope this code should help you.
(You need to add tag ‘Cube’ on your cube game object)

    bool isRotating = true;
	
	void Update () {

        if (Input.GetMouseButtonDown(0)) {

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {

                if (hit.collider.CompareTag("Cube")) {
                    isRotating = false;
                }
                
            }
            
        }

        if (Input.GetMouseButtonUp(0)) {
            isRotating = true;
        }

        if (isRotating) {
            transform.Rotate(Vector3.up * 10 * Time.deltaTime);
        }
            
	}

thanks for the reply
when cube touch my collider then stop or move my cube, i m trying many code but still not working
i take a four obstacle

Image:


code:

public class MoveCube : MonoBehaviour
{
    Rigidbody2D rigidbody2d;
    public float speed = 0.01f;
    //bool mycollider;
    bool mycube;

    void Update()
    {
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
            transform.Translate(touchDeltaPosition.x * speed * Time.deltaTime, touchDeltaPosition.y * speed * Time.deltaTime, 0);
        }
    }
}

I see you are currently working in 2D mode, and without precise details it might not quite be enough. However, make sure that all of your objects have a BoxCollider2D on them, as well as a Rigidbody2D component. If they have both of these on them and it still doesn’t work let me know.