- Home /
How to set to game objects's position from 2 different game objects arrays equal to each other?
Hello everyone, I am trying to compare a game object's original position (starting position) to its current position. I start off by getting all of the game object's tagged with "puzzle" then throw them into a game object array (this should hold of their starting positions) then when the player dies I then create a new game object array which gets me the current position of the game objects tagged with "Puzzle". What i am trying to do is compare the starting position to the current position and reset the active object in the scene to the original position, as if we were to restart the level. Can anyone help with this? Thanks in advance!
public class ResetPuzzle : MonoBehaviour
{
public bool dead = false;
private Vector3 currentCheckPoint;
private GameObject Player;
private GameObject[] puzzle;
private GameObject[] activeObjects;
// Use this for initialization
void Start()
{
puzzle = GameObject.FindGameObjectsWithTag("Puzzle");
Player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update()
{
if (dead == true)
{
activeObjects = GameObject.FindGameObjectsWithTag("Puzzle");
DisablePuzzle();
PuzzleReset();
}
}
public void DisablePuzzle()
{
foreach (GameObject active in activeObjects)
{
active.SetActive(false);
}
}
public void PuzzleReset()
{
foreach (GameObject p in puzzle)
{
foreach (GameObject a in activeObjects)
{
if (a.name == p.name)
{
a.GetComponent<Transform>().position = p.GetComponent<Transform>().position;
a.GetComponent<Transform>().rotation = p.GetComponent<Transform>().rotation;
a.SetActive(true);
}
}
}
dead = false;
Respawn();
}
void Respawn()
{
Player.transform.position = currentCheckPoint;
}
}
Answer by KennethMarshall2018 · Jul 10, 2018 at 10:11 AM
I bet this is the answer to your question https://answers.unity.com/questions/940177/c-store-compare-start-position-and-actual-position.html or https://domyhomeworkonline.net also describes similar code.
In Java, clusters are five star objects. In the above program, arr1 and arr2 are two references to two unique items. So when we look at arr1 and arr2, two reference factors are thought about, accordingly we get the yield as "Not Same". http://www.domyassignmentforme.com