Skip to main content
deleted 4 characters in body
Source Link
derHugo
  • 92.6k
  • 9
  • 94
  • 141

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { // scale should be 1,1,1 by default // The other two can keep their default values scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

Note that Add can not be used outside of a method.


If you rather want to directly initialize your list with some elements added you could go like

 public List<TransformData> matrices1 = new List<TransformData>()  {   new TransformData(somePosition, someRotation, scaleVector);  }; 

if somePosition and someRotation are e.g. also values you get from the Inspector. You can't use transform.position etc outside of a method.

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { // scale should be 1,1,1 by default // The other two can keep their default values scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

Note that Add can not be used outside of a method.


If you rather want to directly initialize your list with some elements added you could go like

 public List<TransformData> matrices1 = new List<TransformData>()  {   new TransformData(somePosition, someRotation, scaleVector);  }; 

if somePosition and someRotation are e.g. also values you get from the Inspector. You can't use transform.position etc outside of a method.

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { // scale should be 1,1,1 by default // The other two can keep their default values scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

Note that Add can not be used outside of a method.


If you rather want to directly initialize your list with some elements added you could go like

public List<TransformData> matrices1 = new List<TransformData>() { new TransformData(somePosition, someRotation, scaleVector); }; 

if somePosition and someRotation are e.g. also values you get from the Inspector. You can't use transform.position etc outside of a method.

added 174 characters in body
Source Link
derHugo
  • 92.6k
  • 9
  • 94
  • 141

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { // scale should be 1,1,1 by default // The other two can keep their default values scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

Note that Add can not be used outside of a method.


If you rather want to directly initialize your list with some elements added you could go like

private void Start() { public List<TransformData> matrices1 = new List<TransformData>()   {   new TransformData(transform.positionsomePosition, transform.rotationsomeRotation, scaleVector);   }; } 

if somePosition and someRotation are e.g. also values you get from the Inspector. You can't use transform.position etc outside of a method.

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

If you rather want to directly initialize your list with some elements added you could go like

private void Start() {  matrices1 = new List<TransformData>()   {   new TransformData(transform.position, transform.rotation, scaleVector);   }; } 

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { // scale should be 1,1,1 by default // The other two can keep their default values scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

Note that Add can not be used outside of a method.


If you rather want to directly initialize your list with some elements added you could go like

 public List<TransformData> matrices1 = new List<TransformData>() { new TransformData(somePosition, someRotation, scaleVector); }; 

if somePosition and someRotation are e.g. also values you get from the Inspector. You can't use transform.position etc outside of a method.

Source Link
derHugo
  • 92.6k
  • 9
  • 94
  • 141

You should give it a constructor like

// In order to be able to actually save that list this class has to be // Serializable! // Another nice side effect is that from now you can also adjust the values // from the Inspector of the MonoBehaviour using such an instance or list [Serializable] public class TransformData { public Vector3 position; public Quaternion rotation; public Vector3 scale; // Serialization always needs a default constructor // doesn't have to do anything but can public TransformData() { scale = Vector3.one; } public TransformData(Vector3 pos, Quaternion rot, Vector3 scal) { position = pos; rotation = rot; scale = scal; } } 

and then do e.g.

// this is a vector not a float! public Vector3 scaleVector = Vector3.one; private void Start() { // I guess you wanted to add the data for some transform component matrices1.Add(new TransformData(transform.position, transform.rotation, Vector3.one)); } 

If you rather want to directly initialize your list with some elements added you could go like

private void Start() { matrices1 = new List<TransformData>() { new TransformData(transform.position, transform.rotation, scaleVector); }; }