- Home /
How to make my puzzle turned until the rotation i want and it will stop?
Please help.
Question 1:My game is a 2D puzzle game that need to rotate the game object and until a certain angle, the box will stopped and not move again, for example game like "Plumber Game". I tried to use box colider 2D to make the connect point between the image i put in, but I don't know what to do in c# part.
Question 2: My puzzle should be randomize angle at the start of the game, how can i randomize it?
Please help me. Thank you.
I'm guessing from "Plumber Game" that you're referring to Pipe $$anonymous$$ania/Pipe Dream. Just leaving a link here for reference on the game/genre.
https://en.wikipedia.org/wiki/Pipe_$$anonymous$$ania
That's not the game he's referring to. He's referring to this game https://www.mathsisfun.com/games/plumber-game.html which is called "Plumber Game".
Answer by sean244 · Apr 14, 2018 at 07:20 PM
Attach the following script to your gamobject. It'll randomize the rotation of the object at the start of the game by a factor of 90 degrees, and then rotate the object by 90 degrees (clockwise) each time you click on it.
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class Puzzle : MonoBehaviour
{
private void Start()
{
Shuffle();
}
private void OnMouseDown()
{
Rotate();
}
private void Shuffle()
{
float randomAngle = 90 * Random.Range(1, 4);
transform.Rotate(new Vector3(0f, 0f, randomAngle));
}
private void Rotate()
{
transform.Rotate(new Vector3(0f, 0f, -90f));
}
}
Note that in order for OnMouseDown to work, a collider must be attached to your object.
If this answer was helpful, please click 'Accept'.
Answer by Amon · Apr 12, 2018 at 03:37 AM
Look at the Mathf.Clamp function. It might be what you are looking for.
I'm not really sure what you talking about but... is there any link/tutorial to it? Sorry, I'm not really experience user...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Rotate Texture Over Time 1 Answer
Mixing mecanim movement with script rotation problem 1 Answer