Вы не можете.lossyScale
равно ReadOnly .
Вам необходимо вручную рассчитать необходимую вам относительную шкалу и затем установить ее с помощью localScale
.
Или, поскольку вы создаете экземпляр объекта, вы можете просто сначала правильно его масштабировать, а затем связать его с проигрывателем, например
// without a parent parameter this is instantiated under the Scene root
var newObject = Instantiate(prefab);
// set the position and rotation
newObject.position = thePlayerObject.position;
newObject.rotation = thePlayerObject.rotation;
// set the desired world scale
newObject.transform.localScale = XYZ;
// parent it to the Player keeping the current world scale
newObject.parent = thePlayerObject.transform;
// equals
//newObject.SetParent(thePlayerObject.transform);
transform.parent = XYZ;
, равный Transform.SetParent(XYZ);
который использует по умолчанию true
в качестве второго параметра, который означает: текущая мировая позиция, вращение и масштаб должны остаться.
Одно альтернативное решение при условии здесь отключил объект, установивон масштабируется, а затем снова становится родительским, сохраняя текущий lossyScale:
// store current parent
Transform oldParent = transform.parent;
// unparent / move to the Scene root level
transform.parent = null;
// Set desired scale in world scale
transform.localScale = XXX;
// parent to the before stored parent again
// keeping the current world scale
transform.parent = oldParent;