- Home /
How to get value from spawned game object and give to another script?
Hi there, i have read a lot about this thing and i cant find a way to fix it. I am building a game and have a game objects ( tiles ) . In every tile theres is the script Tile Length , i made a public float tileLength. Example tile1 tileLength = 2, tile2 tileLength = 6. I wanted to have many tiles with different float value . And that value to change value in other script that have tileLenth when is created by TileManager. How i can get the value from the tiles that are created from TileManager change a value tuleLength ? Thanks in advance.
Answer by xxmariofer · Mar 24, 2020 at 08:52 PM
you could use this in the tile manager script, this is an example that sets all tileLeght tiles to 1
void Start()
{
TileLength[] tiles = FindObjectsOfType<TileLength>();
foreach(TileLength iterator in tiles)
{
iterator.tileLength = 1;
}
}
But if i want from spawned tiles to change value in the tile manager how to do it ?
You just need to find a reference to the mánager script from the times, you can use GameObject.Find, drag and drop from inspector, create an static instance of the mánager you just need a reference
Your answer
Follow this Question
Related Questions
Getting last sprite from prefab. 1 Answer
How to reference a prefab to the script that doesn't exist in Hierarchy 0 Answers
Prefab Puzzle 1 Answer
SetActive() not working 0 Answers
When building a game, are unused prefabs and scripts affected? 1 Answer