using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Parent : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
List<IGet> gets = new List<IGet>();
ChildObj c = new ChildObj();
ParentObj p = new ParentObj();
gets.Add(c);
gets.Add(p);
foreach(var v in gets)
{
if( v is ChildObj)
{
ChildObj ch = v as ChildObj;
Debug.Log("--" + ch.GetValue());//--child
}
Debug.Log("--" + v.GetValue());
}
}
// Update is called once per frame
void Update()
{
}
}
public interface IGet
{
string GetValue();
}
public class ParentObj : IGet
{
private string p= "parent";
public string GetValue()
{
return p;
}
}
public class ChildObj : ParentObj
{
private string p = "child";
new public string GetValue()
{
return p;
}
}