U
U
Uncle Bogdan2021-08-08 09:51:09
Unity
Uncle Bogdan, 2021-08-08 09:51:09

How to make properties appear in the inspector?

Gentlemen, such a problem. My class implements an interface. In the interface, I wrote two properties Name and CompanyName.

I wrote this in class:

using UnityEngine;

public class Processor : MonoBehaviour, IComponent
{
    [SerializeField] int _name;
    [SerializeField] int _companyName;
    public string Name { get; set; }
    public string CompanyName { get; set; }
}


And here is the interface code:

interface IComponent
{
    public string Name { get; set; }
    public string CompanyName { get; set; }


But how to make Name equal to _name?

To change the value of _name in the inspector. And then in another class I was able to make it work fine:

Text.text = processor.Name;

Or do you need to write these two variables for each component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-08-08
@GavriKos

as a variant not to be perverted with properties - to use base class instead of the interface. In it, identify those data that are common. Straight SerializeField

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question