实例化的预制件尺寸太大 Unity C#
Instantiated prefab size is too big Unity C#
当我实例化预制件时
copyOfSpellObject = (GameObject)Instantiate(gameObject, transform.position, transform.rotation);
Item_Spell itemSpell = copyOfSpellObject.GetComponent<Item_Spell>();
itemSpell.SpellObject = GetComponent<Item_Spell>().SpellObject;
copyOfSpellObject.transform.SetParent(transform, false);
copyOfSpellObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(transform.position.x, transform.position.y, 0));
copyOfSpellObject.transform.SetParent(transform.parent.parent.parent, false);
变得超大
正常 - http://prntscr.com/btgzg7
这是为什么?仅当我将游戏对象作为 child 放置到特定的 parent 时才会出现问题,更具体地说,此后的每个 parent 都会导致问题,包括此 transform.parent.parent.parent
。
实例化后单击层次结构中的对象。您是否在 'scale' 属性(在转换组件中)中看到任何大数字?如果这样做,请尝试将这些数字全部设置为 1,看看这是否是您想要的大小。然后只需在您的代码中将对象的比例设置为 1(或您喜欢的任何大小),如下所示:
copyOfSpellObject = (GameObject)Instantiate(gameObject, transform.position, transform.rotation);
Item_Spell itemSpell = copyOfSpellObject.GetComponent<Item_Spell>();
itemSpell.SpellObject = GetComponent<Item_Spell>().SpellObject;
copyOfSpellObject.transform.SetParent(transform, false);
copyOfSpellObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(transform.position.x, transform.position.y, 0));
copyOfSpellObject.transform.SetParent(transform.parent.parent.parent, false);
copyOfSpellObject.transform.localScale = new Vector3(1,1,1);
当最初创建的实例化对象没有父对象时,转换往往会变得非常奇怪。
如果有帮助请告诉我
当我实例化预制件时
copyOfSpellObject = (GameObject)Instantiate(gameObject, transform.position, transform.rotation);
Item_Spell itemSpell = copyOfSpellObject.GetComponent<Item_Spell>();
itemSpell.SpellObject = GetComponent<Item_Spell>().SpellObject;
copyOfSpellObject.transform.SetParent(transform, false);
copyOfSpellObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(transform.position.x, transform.position.y, 0));
copyOfSpellObject.transform.SetParent(transform.parent.parent.parent, false);
变得超大
正常 - http://prntscr.com/btgzg7
这是为什么?仅当我将游戏对象作为 child 放置到特定的 parent 时才会出现问题,更具体地说,此后的每个 parent 都会导致问题,包括此 transform.parent.parent.parent
。
实例化后单击层次结构中的对象。您是否在 'scale' 属性(在转换组件中)中看到任何大数字?如果这样做,请尝试将这些数字全部设置为 1,看看这是否是您想要的大小。然后只需在您的代码中将对象的比例设置为 1(或您喜欢的任何大小),如下所示:
copyOfSpellObject = (GameObject)Instantiate(gameObject, transform.position, transform.rotation);
Item_Spell itemSpell = copyOfSpellObject.GetComponent<Item_Spell>();
itemSpell.SpellObject = GetComponent<Item_Spell>().SpellObject;
copyOfSpellObject.transform.SetParent(transform, false);
copyOfSpellObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(transform.position.x, transform.position.y, 0));
copyOfSpellObject.transform.SetParent(transform.parent.parent.parent, false);
copyOfSpellObject.transform.localScale = new Vector3(1,1,1);
当最初创建的实例化对象没有父对象时,转换往往会变得非常奇怪。
如果有帮助请告诉我