- Home /
How to change Game Object Coloring to Spirte Coloring?
Hey! I am trying to change a Script so that it is using Sprite Renderers instead of Game Objects. The Script Colors the Game Object to red when it is not placable and green when its placeabke here is the line:
protected void SetColor(GridPosition pos) {
if (BuildingModeGrid.GetInstance().CanObjectBePlacedAtPosition(building, pos)) {
foreach(GameObject go in components) {
go.renderer.material.color = new Color(0.25f,1,0.25f,1);
}
} else {
foreach(GameObject go in components) {
go.renderer.material.color = new Color(1,0.25f,0.25f,1);
}
}
}
how do I have to change the script from coloring game Objects to Coloring Sprites?
Answer by Eric5h5 · Mar 17, 2014 at 02:18 PM
Sprites are GameObjects; they just use a SpriteRenderer instead of a MeshRenderer. So "sprite renderers instead of game objects" isn't something that really makes sense. Your code doesn't need any changes.
thanks for clearing that up. but somehow the code do not work with Sprites but with Game Objects. it changes the $$anonymous$$aterial $$anonymous$$ain Color to Red or Green but not the Sprite Color
could you maybe show me in the code where i have to place it? :)
foreach(GameObject go in components) { GetComponent(SpriteRenderer).color. = new Color(0.25f,1,0.25f,1);
doesent work
ok. thanks. looks like this now: go.GetComponent().color = new Color(0.25f,1,0.25f,1); sadly its not changing the color at runtime but at least i have no errors anymore