- Home /
How to detect whether the object's position is change?
Hi, I need your help. I try to write little games for children. In my game, users should combine the cube after choosing the right face and direction in terms of the card. In my code, after placing the cube, the drag-drop script is deactivated because, when I do not do this, the game also works on the turns of the cubes, so it gives wrong results. I could not understand why happened so. How can fix that problem? The user can change the location of the cube after placing it in an area. For this reason, the script needs to be activated again. How can I do that? Could you help me?
public void OyunKontrolu()
{
foreach (GameObject alan in GameObject.FindGameObjectsWithTag("GameCard"))
{
Collider col = alan.GetComponent<BoxCollider>();
float distance= Vector3.Distance(alan.transform.position, transform.position);
if (distance<= 4 && distance>= 0)
{
this.enabled = false; // Deactive the script
if (whichCubesFace.name == gameArea.name)
{
switch (gameObject.name)
{
case "Cube1":
if (transform.localEulerAngles.x == 0 && transform.localEulerAngles.y == 0 && transform.localEulerAngles.z == 180)
{
Debug.Log(whichCubesFace.name + " True");
}
else
{
Debug.Log(whichCubesFace.name + " Wrong");
skor.countInfo(); // Using the another script's method.
col.isTrigger = true;
}
break;
case "Cube2":
if (transform.localEulerAngles.x == 0 && transform.localEulerAngles.y == 90 && transform.localEulerAngles.z == 180)
{
Debug.Log(whichCubesFace.name + " True");
}
else
{
Debug.Log(whichCubesFace.name + " Wrong");
skor.countInfo();
col.isTrigger = true;
}
break;
}
}
else
{
Debug.Log(whichCubesFace.name + " Wrong");
skor.countInfo();
col.isTrigger = true;
}
skor.coutnUp();
break;
}
}
}
Your answer
Follow this Question
Related Questions
How to activate hidden object which in game area in terms of cubes which are dragged and dropped? 0 Answers
character push and drag box 0 Answers
Generating Meshes Is Slow 1 Answer
How do I make an enemy? 1 Answer
Walking on a cube 2 Answers