public void OnMouseDown() { //access the GUI script to check that the simulation has not been started //and the getDoors script to access add/remove doors GameObject plane = GameObject.FindGameObjectWithTag("plane"); script = (GUIScript)plane.GetComponent("GUIScript"); doorScript = (getDoors)plane.GetComponent("getDoors"); GameObject door = getDoor(this.name); //if the animation has not been started yet and the user has clicked on a door //either add or remove door from list of doors //change colour to let user know the door has been blocked //the check to see if there is at least one door open at all times is done in //getDoors script, so no need to check again here if (script.start == false && door != null) { if (check == 1) { check = 0; this.renderer.material.color = Color.green; this.renderer.material.color -= new Color(0, 0, 0, .50f); doorScript.addDoor(door); } else { if (doorScript.removeDoor(door)) { check = 1; this.renderer.material.color = Color.red; this.renderer.material.color -= new Color(0, 0, 0, .50f); } } } }
public void OnMouseDown() { //access the GUI script to check that the simulation has not been started //and the getDoors script to access add/remove doors GameObject plane = GameObject.FindGameObjectWithTag("plane"); script =(GUIScript) plane.GetComponent("GUIScript"); doorScript =(getDoors) plane.GetComponent("getDoors"); GameObject door = getDoor(this.name); //if the animation has not been started yet and the user has clicked on a door //either add or remove door from list of doors //change colour to let user know the door has been blocked //the check to see if there is at least one door open at all times is done in //getDoors script, so no need to check again here if (script.start == false && door != null) if (check == 1){ check=0; this.renderer.material.color = Color.green; this.renderer.material.color -= new Color(0,0,0,.50f); doorScript.addDoor(door); } else { if (doorScript.removeDoor(door)){ check=1; this.renderer.material.color = Color.red; this.renderer.material.color -= new Color(0,0,0,.50f); } } }
public void calculateDoor() { //calculates closest door from the middle of the aisle Vector3 positionMiddle = new Vector3((float)17.56, transform.position.y, transform.position.z); //get the position of all the doors in the model GameObject plane = GameObject.FindGameObjectWithTag("plane"); //get list of doors from script that allows adding and removing of doors doorScript =(getDoors) plane.GetComponent("getDoors"); doorslist = doorScript.doorslist; //calculate and assign an initial door float minDistance = Vector3.Distance(transform.position, doorslist[0].transform.position); string doorName=doorslist[0].name; targetPosition = doorslist[0].transform.position; string doorName2 = null; Vector3 targetPosition2 = new Vector3(0,0,0); int i=1; //going through all the doors in the list, calculate which is closer while (i<doorslist.Count){ float distance=Vector3.Distance(transform.position, doorslist[i].transform.position); float distance2=Vector3.Distance(positionMiddle, doorslist[i].transform.position); //if distance is less than minimum distance, assign a new closest door if (distance < minDistance){ doorName=doorslist[i].name; minDistance=distance; targetPosition=doorslist[i].transform.position; //if the distance from the middle of the aisle is less than the one //calculated above, keep track of doorname and position if (distance2 < distance){ doorName2=doorslist[i].name; targetPosition2=doorslist[i].transform.position; } } i++; } RAINAgent ai=GetComponent<RAINAgent>(); if (ai!=null){ //generate a random number if (Random.Range(0, 100) < 50 && doorName2 != null){ //if number is < 50 and there is a closer door, assign it to the passenger ai.Agent.actionContext.SetContextItem<Vector3>("door", targetPosition2); ai.Agent.actionContext.SetContextItem<string>("doorName", doorName2); } else { //add the initial door ai.Agent.actionContext.SetContextItem<Vector3>("door", targetPosition); ai.Agent.actionContext.SetContextItem<string>("doorName", doorName); } string type = ai.Agent.actionContext.GetContextItem<string>("type"); //add trigger script to passenger if he is of type "altruism" if (type == "altruism"){ Debug.Log ("trigpass"); this.gameObject.AddComponent("trigPass"); } } else print ("null"); }
public void calculateDoor() { //calculates closest door from the middle of the aisle Vector3 positionMiddle = new Vector3((float)17.56, transform.position.y, transform.position.z); //get the position of all the doors in the model GameObject plane = GameObject.FindGameObjectWithTag("plane"); //get list of doors from script that allows adding and removing of doors doorScript = (getDoors)plane.GetComponent("getDoors"); doorslist = doorScript.doorslist; //calculate and assign an initial door float minDistance = Vector3.Distance(transform.position, doorslist[0].transform.position); string doorName = doorslist[0].name; targetPosition = doorslist[0].transform.position; string doorName2 = null; Vector3 targetPosition2 = new Vector3(0, 0, 0); int i = 1; //going through all the doors in the list, calculate which is closer while (i < doorslist.Count) { float distance = Vector3.Distance(transform.position, doorslist[i].transform.position); float distance2 = Vector3.Distance(positionMiddle, doorslist[i].transform.position); //if distance is less than minimum distance, assign a new closest door if (distance < minDistance) { doorName = doorslist[i].name; minDistance = distance; targetPosition = doorslist[i].transform.position; //if the distance from the middle of the aisle is less than the one //calculated above, keep track of doorname and position if (distance2 < distance) { doorName2 = doorslist[i].name; targetPosition2 = doorslist[i].transform.position; } } i++; } RAINAgent ai = GetComponent <RAINAgent>(); if (ai != null) { //generate a random number if (Random.Range(0, 100) < 50 && doorName2 != null) { //if number is < 50 and there is a closer door, assign it to the passenger ai.Agent.actionContext.SetContextItem <Vector3>("door", targetPosition2); ai.Agent.actionContext.SetContextItem <string>("doorName", doorName2); } else { //add the initial door ai.Agent.actionContext.SetContextItem <Vector3>("door", targetPosition); ai.Agent.actionContext.SetContextItem <string>("doorName", doorName); } string type = ai.Agent.actionContext.GetContextItem <string>("type"); //add trigger script to passenger if he is of type "altruism" if (type == "altruism") { Debug.Log("trigpass"); this.gameObject.AddComponent("trigPass"); } } else { print("null"); } }