- Home /
The question is answered, right answer was accepted
Need help equating the values of variables between objects,Need help equating values between objects
I am making a Tic Tac Toe game and have 2 game objects. A "Square" class that is attached to a Box Collider that detects when it's clicked so that it may spawn a symbol of the player who clicked it. It also has the row number, the column number and the index of the individiual Square in the Grid.
I also have a "Pieces" class that is attached to the Cross and Circle 3d models that are prefabs. In that class I have method that destroys the piece from the board should a player want to destroy a piece. It also has the row number, column number and index.
The player symbol is instantiated in the GameManager class.
However, I have trouble equating the index/row&column numbers of the Square and the Symbol. I have tried using "piece.index = square.index;" (piece being the instanced piece and square being the selected symbol), "piece.r = square.r;" / "piece.r = square.r;"
Viewing the equating using Debug.Log, I found out that they would equate, but when viewing the spawned object in the hierarchy view the values were wrong.,I am making a Tic Tac Toe game and have 2 game objects. A "Square" class that is attached to a Box Collider that detects when it's clicked so that it may spawn a symbol of the player who clicked it. It also has the row number, the column number and the index of the individiual Square in the Grid.
I also have a "Pieces" class that is attached to the Cross and Circle 3d models that are prefabs. In that class I have method that destroys the piece from the board should a player want to destroy a piece. It also has the row number, column number and index.
The player symbol is instantiated in the GameManager class.
However, I have trouble equating the index/row&column numbers of the Square and the Symbol. I have tried using "piece.index = square.index;" (piece being the instanced piece and square being the selected symbol), "piece.r = square.r;" / "piece.r = square.r;"
Viewing the equating using Debug.Log, I found out that they would equate, but when viewing the spawned object in the hierarchy view the values were wrong.
Answer by vit3z · Jan 15, 2018 at 02:20 PM
How do I close the question, I figured it out. I needed to create a new Pieces variable and instantiate on it:
instantiatedP = Instantiate(piece, other.gameObject.transform.position, Quaternion.identity);
And assign the index of the square on it:
instantiatedP.index = other.index;
Follow this Question
Related Questions
C# taking variable from other script 2 Answers
Accessing Scripts and Their Variables from other Objects 3 Answers
Getting an object from another script... 1 Answer
Set variable into object and conferring but object Math game 0 Answers
The name 'GameObject' does not denote a valid type ('not found'). BCE0018 0 Answers