Answer the question
In order to leave comments, you need to log in
How to change the sprite in an object on click?
It turned out to change the color of the object to blue when clicked.
But I did not understand how to change the sprite.
It seems in the manual it is described here
And I'm not strong in English
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit)
{
//hit.collider.GetComponent<SpriteRenderer>().color = Color.blue;
hit.collider.GetComponent<SpriteRenderer>().sprite = //? что сюда написать
}
}
}
Answer the question
In order to leave comments, you need to log in
Write in class public Sprite sprite;
Insert a sprite into the editor on this object
And after "=" write "sprite;" there
But you don't need all that. Why? Because without knowing how to use Google, especially without knowing English, you will not go far. you here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question