void MovePeople(GameObject people) { int shoreNum, seatNum; //0为左,1为右 if (people.transform.parent == boat_obj.transform.parent && (boat[0] == null || boat[1] == null)) //物体和船都在同一个岸且船有空位才能上船 { seatNum = boat[0] == null ? 0 : 1; if (people.transform.parent == leftShore_obj.transform) { shoreNum = 0; for (int i = 0; i < LeftObject.Count; i++) { if (people.name == LeftObject[i].name) //左边上船 { actionManager.getOnBoat(people, shoreNum, seatNum); //利用ActionManager LeftObject.Remove(LeftObject[i]); //上船之后游戏对象减少 } } } else { shoreNum = 1; for (int i = 0; i < RightObject.Count; i++) { if (people.name == RightObject[i].name) //右边上船 { actionManager.getOnBoat(people, shoreNum, seatNum); RightObject.Remove(RightObject[i]); //上船之后游戏对象减少 } } } boat[seatNum] = people; people.transform.parent = boat_obj.transform; } else if (people.transform.parent == boat_obj.transform)//点击时物体在船上,选择上岸动作 { shoreNum = boat_obj.transform.parent == leftShore_obj.transform ? 0 : 1; seatNum = (boat[0] != null && boat[0].name == people.name) ? 0 : 1; actionManager.getOffBoat(people, shoreNum); //利用ActionManager boat[seatNum] = null; if (shoreNum == 0) { people.transform.parent = leftShore_obj.transform; LeftObject.Add(people); //左岸对象数目增加 } else { people.transform.parent = rightShore_obj.transform; RightObject.Add(people); //右岸对象数增加 } } }
//对象上船 public void leftShorePriestGoOnBoat(string index) { int temp = 0; for (int i = 0; i < 2; i++) { if (BoatAndCreature[i] == null) { temp++; } } //船停在左边&&船上有空位&&左边岸上还有牧师 if (priestOnLeftshore.Count != 0 && temp != 0 && myDirector.state == State.BOAT_STOP_ON_THE_LEFT_SHORE) { GameObject[] array = priestOnLeftshore.ToArray(); Queue <GameObject> priestOnLeftshore1 = new Queue <GameObject>(); for (int i = 0; i < priestOnLeftshore.Count; i++) { if (array[i].name != index) { priestOnLeftshore1.Enqueue(array[i]); } else { if (BoatAndCreature[0] == null) { BoatAndCreature[0] = array[i]; actionManager.getOnBoat(array[i], 0, 0); } else { BoatAndCreature[1] = array[i]; actionManager.getOnBoat(array[i], 0, 1); } array[i].transform.parent = boat.transform; } } priestOnLeftshore = priestOnLeftshore1; } }