- Home /
How to access an override function into another script (Unity C#)
This is my script
WebSocketNetwork:
public override void GametableHistory(bool success, Int32 gametable_no, Int32 year, Int32 month, Int32 day, Int32 shoe_no, bc_gametable_history_list list)
{
Debug.Log("GametableHistory gametable_history_list.Count = " + list.Count);
string s = "";
for (int i = 0; i < list.Count; i++)
{
s += list[i].r;
s += ",";
}
Debug.Log("Gametable " + gametable_no + " History = " + s);
//PK 4/23/2018
PlayInfo.Instance.gametablehistory = s;
}
WebsocketSession:
abstract public void GametableHistory (bool success, Int32 gametable_no, Int32 year, Int32 month, Int32 day, Int32 shoe_no, gametable_history_list list);
PlayInfo.cs:
public string gametablehistory;
and i have a blank script which is TestScript.cs . What i want here is that on my TestScript.cs
i will call the override function and get the gametable_history_list
but i don't know how should i get it from there. Could someone please guide me.
The compiler will automatically call the bottom implementation of the method. You should look into virtual table. The compiler takes the given type and finds that the called method is virtual/abstract, it will then go down the object hierarchy to find the bottom implementation.
The compiler will never call the base class implementation from outside the class if there is a sub class implementation.
I don't quite understand sir . Could you please explain more.
Answer by Sabre-Runner · Apr 24, 2018 at 07:14 AM
My best suggestion is to put a Property on the WebSocketNetwork script to just get the gametable history you want.
So i should do it like this ?
//this is for the websocket.cs
private string gametablehistory
public string Gametablehistory{
get{ return gametablehistory; }
set{ gametablehistory = value; }
}
//testscript.cs
TestScript GetHistory = new TestScript();
GetHistory.gametablehistory = PlayInfo.Instance.gametablehistory;
Just like this?
Yes. But if you don't want someone from outside overriding your data, don't expose the setter. Or don't have one.
Your answer
![](https://koobas.hobune.stream/wayback/20220612161416im_/https://answers.unity.com/themes/thub/images/avi.jpg)