- Home /
how to stop my cube when touch collider??
when touch collider then stop my cube.....
Answer by nik_bluebird · Apr 19, 2019 at 11:19 AM
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);
}
}
Answer by rahulpatil6220375 · Apr 19, 2019 at 11:52 AM
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);
}
}
}
Answer by Larcondos · Apr 30, 2019 at 02:27 PM
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.
that problem solved but can u give suggestion for.. when the player has filled a shape??
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Using noise to generate Cube World like terrain 0 Answers
highlight cube sides on mouse hover 2 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer