示例#1
0
 // Spawn a boid and set necessary targets
 private void ToggleCollision()
 {
     if (Input.GetKeyDown(KeyCode.Q))
     {
         ConeToggle = !ConeToggle;
         foreach (GameObject GBoid in GreenBoids)
         {
             GBoid.GetComponent <Flock>().addCone = ConeToggle;
         }
         foreach (GameObject RBoid in RedBoids)
         {
             RBoid.GetComponent <Flock>().addCone = ConeToggle;
         }
         ConeText.text = "Cone Check: " + ConeToggle;
     }
     if (Input.GetKeyDown(KeyCode.E))
     {
         PredictionToggle = !PredictionToggle;
         foreach (GameObject GBoid in GreenBoids)
         {
             GBoid.GetComponent <Flock>().addCone = PredictionToggle;
         }
         foreach (GameObject RBoid in RedBoids)
         {
             RBoid.GetComponent <Flock>().addCone = PredictionToggle;
         }
         PredictionText.text = "Collision Prediction: " + PredictionToggle;
     }
 }
示例#2
0
    // On initialization
    void Start()
    {
        GreenBoids = new List <GameObject>();
        RedBoids   = new List <GameObject>();

        // Spawn 2 groups of Boids
        for (int i = 0; i < 6; i++)
        {
            SpawnBoids(GreenBoidPrefab, GreenBoidLead, GreenBoidLead.GetComponent <NPCController>(), GreenBoids);
            SpawnBoids(RedBoidPrefab, RedBoidLead, RedBoidLead.GetComponent <NPCController>(), RedBoids);
        }

        // Set leads to follow path
        GreenBoidLead.GetComponent <PathFollow>().path = GreenBoidPath.GetComponent <PathPlacer>().path;
        RedBoidLead.GetComponent <PathFollow>().path   = RedBoidPath.GetComponent <PathPlacer>().path;

        // Set collision detection
        foreach (GameObject GBoid in GreenBoids)
        {
            foreach (GameObject RBoid in RedBoids)
            {
                GBoid.GetComponent <ConeCheck>().targets.Add(RBoid.GetComponent <NPCController>());
                GBoid.GetComponent <CollisionPrediction>().targets.Add(RBoid.GetComponent <NPCController>());
                RBoid.GetComponent <ConeCheck>().targets.Add(GBoid.GetComponent <NPCController>());
                RBoid.GetComponent <CollisionPrediction>().targets.Add(GBoid.GetComponent <NPCController>());
            }
        }
    }