我正在复制图像,因为它正在被触摸。拖动克隆时,我将原始图像设置为非活动状态。
但是我想从克隆脚本中删除克隆映像后重新激活原始映像。
我可以在实例化克隆时向克隆添加对原始图像的引用。我尝试使用GameObject original = transform.Find(transform.gameObject.name).gameObject;
搜索原始图片,但我认为您找不到停用的GameObjects
public void OnPointerDown(PointerEventData eventData)
{
if (this.gameObject.tag != "Clone")
{
clone = Instantiate(this.gameObject) as GameObject;
clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
clone.transform.position = transform.position;
clone.transform.localScale += new Vector3(0.5F, 0.5F, 0);
clone.gameObject.tag = "Clone";
clone.gameObject.name = transform.gameObject.name;
}
答案 0 :(得分:1)
public void OnPointerDown(PointerEventData eventData)
{
if (this.gameObject.tag != "Clone")
{
clone = Instantiate(this.gameObject) as GameObject;
clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
clone.transform.position = transform.position;
clone.transform.localScale += new Vector3(0.5F, 0.5F, 0);
clone.gameObject.tag = "Clone";
clone.gameObject.name = transform.gameObject.name;
clone.GetComponent<TheCloneScript>().original = this.gameObject; //that's it
}
}
答案 1 :(得分:0)
据我所知,您无法在场景中找到和引用无效的gameobj。 但是我统一进行了一些测试,试图找到不活跃的游戏对象,然后我发现了这一点:
如果原始obj有一个父对象,则可以找到该父对象,然后找到不活动的子对象,如下所示:
GameObject parent = GameObject.Find("test");
GameObject inActiveChild = go.transform.Find("subTest").gameObject;
inActiveChild .SetActive(true);
或者您可以在原始obj仍处于活动状态时引用它,并在需要时再次使用它来使用它。