- Home /
Question by
yuanxindrome · Mar 02, 2020 at 09:34 PM ·
gameobjectprefabspritegetcomponentgetcomponentinchildren
Counter for sprite under script from GameObject prefab
I am trying to create a scoring system by counting the number of sprites within the script component in the prefab. I tagged the prefab as "Tiles".
The part where I added GetComponent(); does not work... I do not want the counter to count the number of prefabs I have, but instead count the number of particular sprites within the prefab. Is the a method? I have 4 sprites under the prefab script component.
Here is my code:
{
GameObject[] Tile = GameObject.FindGameObjectsWithTag("Tiles").GetComponent<Image>();
int numberofTiles = Tile.Length;
ScoreScriptPLAYER2.scoreValue += numberofTiles;
}
Comment
Your answer
Follow this Question
Related Questions
Sporadic Failure of GetComponentInChildren 0 Answers
Convert code to get prefab then sprite ? 0 Answers
I cant get this code to work. What am i doing wrong? 1 Answer
What's the most efficient way to change script from child object 2 Answers
How do I change Sprites (and manipulate the Sprite Object) in C#? 0 Answers