- Home /
Change List name as the "Name" Property in the list
Used
using UnityEngine;
using System;
[Serializable]
public struct Products {
public enum ProductCategory {
FabricSofas,
WoodenSofas,
Leather_LeatheretteSofas
}
public enum SeaterType {
One,
Two,
Three,
ThreeOneOne,
ThreeTwoOne,
ThreeTwoTwo
}
public enum VariantName{
Blue,
Red,
Black,
Brown,
BlahBlahBlah
}
public ProductCategory SelectProductCategory;
public string ProductName;
public SeaterType SelectSeater;
public GameObject VariantPrefab;
public VariantName SelectVariant;
public Sprite VariantIcon;
}
For Products.cs
and
using UnityEngine;
using System.Collections.Generic;
public class ProductsDetails : MonoBehaviour {
public List<Products> ProductsYo = new List<Products>();
}
for ProductsDetails.cs
ProductsDetails.cs will be attached to the GameObject. And I want to change the name of the list from Element0 to Product name entered.,
Also, want to provide buttons to Save this data to JSON and load from JSON to form this array list.
Can someone please let me know what has to be done here? I'm very poor at programming..
Answer by Nikhil12 · Nov 27, 2017 at 11:42 AM
I have done that but with List and class. I defined a string called "name" inside class .Then I defined a List of class objects in my script. In the inspector when I fill the name field for the element0. The "element0" changes to the name I input in the name filled.It worked for me.
You can give it a try.
Great, do you have any idea on,
how to take the name from Enum and change the name of Element0?
or, do you know how do i assign the value of Enum directly to a string field?