Z
Z
Zimaell2020-09-27 18:43:17
Unity
Zimaell, 2020-09-27 18:43:17

How to create a prefab and add properties to it?

The bottom line is, I pass data to the script and a prefab with all the data is created from this data.
I do this for example

int ScaleX = 1;
int ScaleY = 1;
int ScaleZ = 1;

 GameObject NewPrefab = new GameObject(id);
 NewPrefab.AddComponent<Transform>();
 NewPrefab.transform.localScale.x = ScaleX;
 NewPrefab.transform.localScale.y = ScaleY;
 NewPrefab.transform.localScale.z = ScaleZ;

writes to me
Cannot modify the return value of 'Transform.localScale' because it is not a variable

this is not a variable, although I looked in the examples, I seem to have written it correctly ...
and then the question is - how to add variables of different types to this object? (int, string, and public private level)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-09-27
@Zimaell

To the first question:
NewPrefab.transform.localScale = new Vector3(ScaleX, ScaleY, ScaleZ).
On the second - go to teach seasharp first. And then climb into the unit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question