public void Enter(SceneData pScene, Hansel pHansel, Gretel pGretel, Savegame pSavegame) { bool TmpEnterFinished = true; foreach (Waypoint wp in pScene.Waypoints) { if (wp.CollisionBox.Intersects(pHansel.CollisionBox) || wp.CollisionBox.Intersects(pGretel.CollisionBox)) { TmpEnterFinished = false; pHansel.MoveManually(wp.MovementOnEnter, 1f, pScene, false, false, true); pGretel.MoveManually(wp.MovementOnEnter, 1f, pScene, false, false, true); } } if (TmpEnterFinished) { CurrentState = State.Idle; //Spiel speichern wenn Spieler in der Scene angekommen sind und ein Kreidefelsen in ihr steht. foreach (int i in Hardcoded.Scene_Waystone) { if (GameReferenzes.SceneID == i) { Savegame.Save(pSavegame, pHansel, pGretel); } } /* * if (GameReferenzes.SceneID == 3 | GameReferenzes.SceneID == 6 | GameReferenzes.SceneID == 12 | GameReferenzes.SceneID == 15) * Savegame.Save(pSavegame, pHansel, pGretel); * foreach (InteractiveObject iObj in pScene.InteractiveObjects) * { * if (iObj.Name == Hardcoded.Scene_Waystone_IObjName) * { * Savegame.Save(pSavegame, pHansel, pGretel); * } * } */ } }
private void Update() { // save if (Input.GetKeyDown(KeyCode.J)) { Savegame.Save(field, chests, inventory, quickSlots); } // plant an item from quickSLot if (Input.GetButtonDown("UseItem")) { if (!targeter.target && targeter.IsInField()) { UIItem uiItem = quickSlots.GetSelectedItem(); if (uiItem != null) { string itemName = uiItem.item.name; GameObject plant = Plant.CreateObject(new PlantData(itemName, "0", targeter.transform.position)); //GameObject plantToPlace = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Plants/" + itemName)); //plantToPlace.name = itemName + Time.time; plant.transform.parent = field.transform; //plantToPlace.transform.position = targeter.transform.position; //plantToPlace.GetComponent<SpriteRenderer>().sortingOrder = -(int)plantToPlace.transform.position.y; quickSlots.RemoveSelectedItem(); targeter.AddTarget(plant); actionTimeStamp = Time.time; } } } // remove fruit in target if (Input.GetButtonDown("Submit")) { if (targeter.target) { if (targeter.target.name == "Chest") { Chest chest = targeter.target.GetComponent <Chest>(); cUIC.Open(chest); } else { Plant targetPlant = targeter.target.GetComponent <Plant>(); if (targetPlant.data.yield > 0) { Item item = targetPlant.droppedFruit; inventory.AddItem(item, targetPlant.data.yield); Destroy(targeter.target); actionTimeStamp = Time.time; } } } } if (Input.GetButtonDown("Inventory")) { iUIC.Open(); } #region QuickSlot // selects a quickSlot if (Input.GetButtonDown("QuickSlotUp")) { quickSlots.SelectQuickSlot(0); } if (Input.GetButtonDown("QuickSlotRight")) { quickSlots.SelectQuickSlot(1); } if (Input.GetButtonDown("QuickSlotDown")) { quickSlots.SelectQuickSlot(2); } if (Input.GetButtonDown("QuickSlotLeft")) { quickSlots.SelectQuickSlot(3); } #endregion // handle grid navigation if (!moveInGrid) { // set animation if (Input.GetKey(KeyCode.D)) { viewingDirection = Vector3.right; animator.SetBool("moveRight", true); animator.SetBool("moveLeft", false); } else if (Input.GetKey(KeyCode.A)) { viewingDirection = Vector3.left; animator.SetBool("moveRight", false); animator.SetBool("moveLeft", true); } else { animator.SetBool("moveRight", false); animator.SetBool("moveLeft", false); } if (Input.GetKey(KeyCode.W)) { viewingDirection = Vector3.up; animator.SetBool("moveUp", true); animator.SetBool("moveDown", false); } else if (Input.GetKey(KeyCode.S)) { viewingDirection = Vector3.down; animator.SetBool("moveUp", false); animator.SetBool("moveDown", true); } else { animator.SetBool("moveUp", false); animator.SetBool("moveDown", false); } // switch to grid based movement if (Input.GetButtonDown("GridMovement")) { moveInGrid = true; float roundedX = Mathf.Round(transform.position.x); float roundedY = Mathf.Round(transform.position.y); desiredGridPos = new Vector3(roundedX, roundedY); animator.SetBool("moveUp", false); animator.SetBool("moveRight", false); animator.SetBool("moveDown", false); animator.SetBool("moveLeft", false); } } else { // go out of grid based movement if (Input.GetButtonDown("GridMovement")) { moveInGrid = false; } } }