コード例 #1
0
    // create tank
    public GameObject createTank(int[] specs, SimObserver observer, string name)
    {
        GameObject newTank = Instantiate(tankPrefab);

        newTank.GetComponent <TankHealth>().SetHealth((float)specs[0]);
        newTank.GetComponent <TankHealth>().name = name;
        newTank.GetComponent <TankMovement>().SetSpeed((float)specs[1]);
        newTank.GetComponent <TankShooting>().SetStrength((float)specs[2]);
        newTank.GetComponent <TankShooting>().SetStrength((float)specs[2]);
        newTank.GetComponent <TankObservable>().AddObserver(observer);

        newTank.GetComponent <TankObservable>().Notify(name + " just initialized.");

        return(newTank);
    }
コード例 #2
0
    public void Awake()
    {
        gameManager = gameObject.GetComponent <GameManager>();
        simObserver = gameObject.GetComponent <SimObserver>();

        flocks = new TankFlock[2];
        TankFlock newFlock0 = gameObject.AddComponent <TankFlock>() as TankFlock;

        newFlock0.Start();
        flocks[0] = newFlock0;
        TankFlock newFlock1 = gameObject.AddComponent <TankFlock>() as TankFlock;

        newFlock1.Start();
        flocks[1] = newFlock1;

        init = true;
    }
コード例 #3
0
 //Add observer to the list
 public void AddObserver(SimObserver observer)
 {
     observers.Add(observer);
 }