📜  unity 2d 换出背景图像 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:17.707000             🧑  作者: Mango

代码示例1
//You can create a sprite and swap which sprite it is using currently.
//these can be set in editor
public GameObject sprite1;
public GameObject sprite2;

//put following code in function that changes sprites
//this sets both of these to be the opposite of their current state
//SetActive() will set the game object before it to the active state of the
//bool in the parameters.
//activeSelf returns the active state of the given game object
sprite1.SetActive(!sprite.activeSelf);
sprite2.SetActive(!sprite.activeSelf);