Exemple #1
0
    void Start()
    {
        grid = GetComponent<Grid> ();
        borderX = new Vector2 (grid.worldBottomLeft.x, grid.worldBottomLeft.x + grid.gridWorldSize.x); //left and right border
        borderZ = new Vector2 (grid.worldBottomLeft.z, grid.worldBottomLeft.z + grid.gridWorldSize.y); //upper and down border

        thisCheck = thisCheck.GetComponent<checkCollision>();

        //load the buildingprefabs
        GameObject building1 = Resources.Load("Buildings/building1") as GameObject;
        GameObject building2 = (GameObject)Resources.Load ("Buildings/building2");
        GameObject building3 = (GameObject)Resources.Load ("Buildings/building3");
        buildingPrefabs.Add (building1); //+90 degrees in x-axis
        buildingPrefabs.Add (building2); //+90 degrees in x-axis
        buildingPrefabs.Add (building3); //normal

        numPrefabs = buildingPrefabs.Count;
        numBuildings = 200;

        //check every instantiated building
        for (int i =1; i <= numBuildings; i++) {
            thisBuilding =(GameObject)InstantiatePrefab();
            if (thisCheck.fail){
                numBuildings++;
            }
            //Debug.Log(i);
        }
    }
Exemple #2
0
    // Start is called before the first frame update
    public void Start()
    {
        body.gravityScale = 3.5f;
        body.constraints  = RigidbodyConstraints2D.FreezeRotation;


        // BoxCollider2D
        //col.size = new Vector2(1, 1.5f);
        //col.offset = new Vector2(0, -0.25f);

        col = GetComponent <BoxCollider2D>();
        //col.size = new Vector2(1, 2.5f);
        body = GetComponent <Rigidbody2D>();

        runninCompass = new RunDirection("CheckDirection");
        runninLegs    = new RunToward();     //Doesn't have just one string that it responds to.
        eyes          = new Look4Player("lookAround");
        brain         = new Brain();
        chkr          = new checkCollision("checkCollisions");
        chase         = new Chase();
        patrol        = new Patrol();
        walkHelp      = new walk("walkToFarthestEdge");
        runninEyes    = new Check4Edge();
        transition    = new SwitchState();

        brain.setState(patrol);
        brain.setState(chase);

        patrol.setJob("walkToFarthestEdge");     //this should probably be separate from runToPlayer, and slower than that. Should walk to edge of plat.
        patrol.setJob("checkCollisions");        //checks if current velocity is 0
        patrol.setJob("lookAround");
        chase.setJob("CheckDirection");
        chase.setJob("checkCollisions");
        transition.addTrigger("edge");
        transition.addTrigger("turn");        //if checkCollision tells us that we've hit a wall (which usually means turn around) we switch states.
        transition.addResponse("statePatrol");

        brain.setComrade(walkHelp);
        brain.setComrade(eyes);
        brain.setComrade(chkr);
        chkr.setComrade(runninCompass);
        chkr.setComrade(runninLegs);
        runninCompass.setComrade(runninEyes);
        runninCompass.setComrade(transition);

        walkHelp.setLeader(brain);
        eyes.setLeader(brain);
        chkr.setLeader(brain);
        runninCompass.setLeader(runninLegs);
        runninLegs.setLeader(runninEyes);
        runninEyes.setLeader(brain);
        transition.setLeader(brain);

        chkr.setBod(body);
        walkHelp.setBody(body);
        eyes.setBody(body);
        runninLegs.setBody(body);
        runninCompass.setBody(body);
        runninEyes.setBody(body);

        runninLegs.setSpeed(sprint);
        walkHelp.setSpeed(speed);
        eyes.setFollowDist(followDist);
        walkHelp.set_raycast_length(raycast_length);
        runninEyes.set_raycast_length(raycast_length);
    }