Cannot figure out hit detection of drop target. They need to be instantiated? Just going through script and adding solenoids you already have in there, can get most working aside from that.
I suppose this is the problem. It's giving me a different name to what's in FP.
That's normal, you have created 1 bank DropTargets, so in the simulation, they are named YourDropTarget-1.
This is done to differentiate the targets when bank count>1 , so you can find in the bank YourDropTarget-1 , YourDropTarget-2 , YourDropTarget-3 , etc..
You can give a try to this test script.
Creates a table with one DropTarget called "DropTtarget4" with 6 banks.
The script handles target hits and when all targets are down, the bank is reseted
using UnityEngine;
using System.Collections;
public class Script
{
public void Init()
{
GameObject table = GameObject.Find("TABLE");
test_TableManager behaviour = table.AddComponent<test_TableManager>();
behaviour.PreInit(); // Call pre-initialization steps
behaviour.Init(); // Script initialization
behaviour.PostInit(); // Call poste-initialization steps
}
}
public class test_TableManager : BxTableManager
{
//////////////////////////////////////////////////////////////
///////////////////// DropTarget4 dropped ?///////////////////
public bool dt41=false;
public bool dt42=false;
public bool dt43=false;
public bool dt44=false;
public bool dt45=false;
public bool dt46=false;
//! Use this for initialization
public override void Init ()
{
base.Init(); // Call BxVPMTableManager Start (Display version and default controller options
InitArrays(255,255,10,255); // 89 Lamps, 65 Solenoids/Flashers (10 by default for GIs) and 255 Switches...)
InitSubwaySystem(); // Initialize Subway System
AddPlungerBehaviour("Plunger"); // Add plunger behaviour
}
//! Initialize table driver
public override void InitDriver()
{
}
public override void LateUpdate ()
{
base.LateUpdate();
if(Input.GetKeyDown(KeyCode.K))
{
SetSolenoid(4, true); // todo => switch off (will not work when not using changedSolenoidsCallback)
}
////////////////////// Testif all DropTarget4 are dropped
testDT4();
}
//! Initialize Subway System (redefinition)
public override void InitSubwaySystem()
{
// Getting Objects
base.InitSubwaySystem();
GameObject subway = GameObject.Find ("TABLE/SUBWAY");
if(subway==null)
{
Debug.LogError("Unable to find SUBWAY object");
return;
}
BxSwManager subManager = (BxSwManager)subway.GetComponent("BxSwManager");
if(subManager==null) subManager = (BxSwManager)subway.GetComponent("BxSwVisualManager");
if(subManager==null)
{
Debug.LogError("Unable to find the Subway manager component in SUBWAY object");
return;
}
//////////////////////////////////////////////////////////////////////////////
// Subway System building
float swL = Global.Physics.g_BallDiameter; // length of switches in mm
// Main through
BxSwNode drain = subManager.AddEntrance("Drain",5); // Main drain node used as subway entrance
BxSwNode pkick = subManager.AddExit("PlungerKicker",4); // Exit plunger kicker Node
pkick.m_swicthSlot = 52; // Node switch number
BxSwEdge mainThrough = subManager.LinkNodes(drain,pkick,1.5f); // main Through edge link (1.5 seconds for a ball to cross it)
mainThrough.AddSwitch(50, mainThrough.m_length-swL*1.5f, swL*0.9f); // First switch on the edge
mainThrough.AddSwitch(51, mainThrough.m_length-swL*0.5f , swL*0.9f); // Second switch on the edge (making 3 in total with the pkick node switch)
// build the subway system
subManager.Build();
// Insert 10 balls in the main through
for(int i=0;i<1;i++)
{
BxSwVirtualBall b = new BxSwVirtualBall();
drain.InsertBall(b);
subManager.ReportNewBall(b);
subManager.DoStep();
}
}
//! Link lamp array to Unity objects (called by InitArrays)
public override void InitLampsObjects()
{
base.InitLampsObjects(); // call ancestor's function
}
//! Link solenoid array to Unity objects (called by InitArrays)
public override void InitSolenoidsObjects()
{
base.InitSolenoidsObjects(); // call ancestor's function
////////////////// Testing DropTarget4
AddSolenoid("DropTarget4-1", 93, "BxDropTargetSolenoid");
AddSolenoid("DropTarget4-2", 93, "BxDropTargetSolenoid");
AddSolenoid("DropTarget4-3", 93, "BxDropTargetSolenoid");
AddSolenoid("DropTarget4-4", 93, "BxDropTargetSolenoid");
AddSolenoid("DropTarget4-5", 93, "BxDropTargetSolenoid");
AddSolenoid("DropTarget4-6", 93, "BxDropTargetSolenoid");
AddSolenoid("Flippers/RightFlipper" , 46, "BxBasicFlip"); // Right Flipper
AddSolenoid("Flippers/LeftFlipper" , 48, "BxBasicFlip"); // Left Flipper
}
//! Link solenoid array to Unity objects (called by InitArrays)
//! (Must be inherited and use AddSolenoid)
public override void InitSwitchesObjects()
{
base.InitSwitchesObjects(); // call ancestor's function
AddSwitch("DropTarget4-1" , 85 ,"BxDropTargetSwitch");
AddSwitch("DropTarget4-2" , 86 ,"BxDropTargetSwitch");
AddSwitch("DropTarget4-3" , 87 ,"BxDropTargetSwitch");
AddSwitch("DropTarget4-4" , 88 ,"BxDropTargetSwitch");
AddSwitch("DropTarget4-5" , 89 ,"BxDropTargetSwitch");
AddSwitch("DropTarget4-6" , 90 ,"BxDropTargetSwitch");
}
//! ROM Simulation (from input signals to output actions)
public override void SetSwitch (int slot, bool state)
{
base.SetSwitch (slot, state);
switch(slot)
{
///////////////////////DropTarget 4
case 85: dt41=true;break;
case 86: dt42=true;break;
case 87: dt43=true;break;
case 88: dt44=true;break;
case 89: dt45=true;break;
case 90: dt46=true;break;
}
}
//////////////////// Test if all DropTarget4 are dropped->then reset them
void testDT4()
{
if(dt41 & dt42 & dt43 & dt44 & dt45 & dt46)
{
//////////// If all targets down=>reset the bank
SetSolenoid(93,true);
dt41=false;
dt42=false;
dt43=false;
dt44=false;
dt45=false;
dt46=false;
}
}
}