Answer the question
In order to leave comments, you need to log in
How to get the name of an object through its component?
Hello everyone, when developing the game, the following question arose: I have a cell of the earth, and I can dig it. I implemented the digging process in this way: when you press the "dig button", the prefab (there are 10 of them) is replaced by the cell on which the "player's sensors" are now located. But it turned out that I have a lot of such cells on the level, and the prefabs are called the same (each cell of the earth has the same "digging process"), and when you press the dig key, all the cells on the level, and not just the one on which are my character's sensors. I made a script for one of the sensors, which should determine which cell the player is currently looking at and only dig it. Here is the code:
hit = Physics2D.Raycast(this.transform.position, Vector2.down, 1.0f, groundLayer);
if(hit) {
obj = (hit.transform.name).ToString();
Debug.Log(obj);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question