Answer the question
In order to leave comments, you need to log in
Unity: How to display multiple sprites in one object?
How to display multiple sprites for one object?
Let me explain with an example what I want to achieve.
An object, say, a car wheel. It, according to the conditions, should be drawn separately, like a sandwich from sprites:
using UnityEngine;
public class Wheel : MonoBehaviour {
void OnMouseDown(){
???????????
}
}
.GetComponent<SpriteRenderer> ().enabled = true/false
Answer the question
In order to leave comments, you need to log in
but I don't know how to access the SpriteRenderer of the child object.
If the caps and wheels differ only in texture. then I would suggest doing a more optimal thing
using UnityEngine;
public class Wheel : MonoBehaviour {
public Texture[] textures;
public Sprite targetSprite;
void OnMouseDown(){
targetSprite.sprite = textures[0]; // или любой другой номер или логика выбора.
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question