'Having trouble passing data through Lists
What i wanted to do
I have a class (BlackBoard) that holdes data. and class NPC Gets the data from (BlackBoard). (NPC_Guard) inherits from (NPC) which uses (NPC_Movement) to move by using the data from (BlackBoard).
BlackBoard class
public sealed class BlackBoard : MonoBehaviour
{
#region Singleton
private static BlackBoard instance = null;
public static BlackBoard Instance
{
get
{
if (instance == null)
{
instance = new BlackBoard();
}
return instance;
}
}
#endregion
[SerializeField] List<Transform> NavigationPoints = new List<Transform>();
public List<Transform> Get_NavigationPoints() => NavigationPoints;
public void Set_NavigationPoints(List<Transform> T) => NavigationPoints = T;
}
NPC_Movement class
public class NPC_Movement
{
Vector3 direction;
List<Transform> _navigationPoints = null;
[SerializeField] public List<Transform> NavigationPoints;
{
get
{
if (_navigationPoints == null)
{
_navigationPoints = BlackBoard.Get_NavigationPoints();
}
return _navigationPoints;
}
}
BlackBoard BlackBoard = BlackBoard.Instance;
public void Move()
{
// A complex movement function which uses NavigationPoints
}
}
NPC class
public abstract class NPC : MonoBehaviour
{
[SerializeField] protected NPC_Movement Movement;
}
NPC_Guard class
public class NPC_Guard : NPC
{
void Update()
{
Movement.Move();
}
}
Problem
NPC_Movement class does not get the NavigationPoints List .
What am i doing wrong
please help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
