Hi . I want to use ny new class like
new Relation(a string,an int, another int);
but when i did this it returns null
[Serializable]
public class Relation
{
public int id;
public string name;
public int value;
public Relation(int id, string name, int value)
{
}
}
Give this a go.
[Serializable]
public class Relation
{
public int id;
public string name;
public int value;
public Relation(int _id, string _name, _int value)
{
_id = id;
_name = name;
_value = value;
}
}
Honestly, creating a class to be used is far less efficient than using things like polymorphism or good ol’ inheritance. However, when you create a new script, you create a new class that can be used at any time as long as you have a reference to that script. Although here is something you can do by using Polymorphism that may help.
using System;
using UnityEngine;
[Serializable] public class Parent:MonoBehaviour {
//some code and functions
}
Then,
using System;
using UnityEngine;
public class Child:Parent {
//some code and functions
}