void Start() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> (); productNamesByIndex = new string[][] { //tools (0) new string[] { "flintAxe", "flintPickaxe" }, //buildings (1) new string[] { "campfire" }, //materials (2) new string[] { "rope" }, //weapons (3) new string[] { }, //clothing (4) new string[] { }, //food (5) new string[] { }, //special (6) new string[] { } }; setRecipe(); }
public void SkinUnlockOrEquip(int catNumber, int skinNumber) { playerDetails = gameDataObject.GetComponent <PlayerDetailsScript>(); playerInv = gameDataObject.GetComponent <PlayerInventoryScript>(); playerStable = gameDataObject.GetComponent <PlayerStableScript>(); Debug.Log(playerInv.catSkins[skinNumber]); int skinStatus = playerInv.catsUnlocked[catNumber]; //Grab the status of the skin if (skinStatus == 1) //If we own it { playerStable.currentCat = catNumber; //Equip it catSpawn.DeleteCat(); catSpawn.SpawnOwnCat(); //Code to refresh cat here } if (skinStatus == 0) { if (playerDetails.hardCurrency >= 500) //If we can afford it { playerDetails.hardCurrency -= 500; //Buy it playerInv.catsUnlocked[catNumber] = 1; //Register it in inventory SkinUnlockOrEquip(catNumber, skinNumber); } } }
void Start() { GameObject playerGO = PlayerManager.instance.player.gameObject; playerRb = playerGO.GetComponent <Rigidbody>(); playerInventoryScript = playerGO.GetComponent <PlayerInventoryScript>(); }
// Start is called before the first frame update void Start() { gss = gameObject.GetComponent <GameScoreScript>(); hps = gameObject.GetComponent <HealthPointsScript>(); pis = gameObject.GetComponent <PlayerInventoryScript>(); pc = gameObject.GetComponent <PlayerController>(); }
// Use this for initialization void Start() { gameDataObject = GameObject.FindGameObjectWithTag("GameData"); gameOptions = gameDataObject.GetComponent <GameOptionsScript>(); playerDetails = gameDataObject.GetComponent <PlayerDetailsScript>(); playerInv = gameDataObject.GetComponent <PlayerInventoryScript>(); playerStable = gameDataObject.GetComponent <PlayerStableScript>(); }
// Use this for initialization void Start() { playerInv = gameObject.GetComponent <PlayerInventoryScript>(); catName = new string[playerInv.numberOfCats]; catSkinCurrent = new int[playerInv.numberOfCats]; catHeadCurrent = new int[playerInv.numberOfCats]; catCollarCurrent = new int[playerInv.numberOfCats]; }
// Use this for initialization void Start() { inventory = GameObject.Find ("Player").GetComponent<PlayerInventoryScript>(); panel = transform.Find("Panel").gameObject; panel.SetActive (false); panelShown = false; //otherCamera.gameObject.SetActive (false); }
void Start() { player = GameObject.Find("Player"); playerInventoryScript = player.GetComponent <PlayerInventoryScript> (); rightFrontLeg = transform.GetChild(1).gameObject; leftFrontLeg = transform.GetChild(2).gameObject; rightBackLeg = transform.GetChild(3).gameObject; leftBackLeg = transform.GetChild(0).gameObject; }
void Start() { player = GameObject.Find("Player"); playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript>(); if (cut) { for (int i = 0; i <= 26; i++) { transform.GetChild(i).GetComponent <Renderer> ().enabled = false; } } }
void Awake() { if (instance == null) { instance = this; } else { Destroy(this.gameObject); } DontDestroyOnLoad(this.gameObject); }
void Start() { player = GameObject.Find("Player"); playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript>(); for (int i = 0; i < 16; i++) { transform.GetChild(i).position = new Vector3(transform.GetChild(i).position.x + Random.Range(0f, 0.2f), transform.GetChild(i).position.y + Random.Range(0.6f, 1.1f), transform.GetChild(i).position.z + Random.Range(0f, 0.2f)); float scale = Random.Range(1f, 1.6f); transform.GetChild(i).localScale = new Vector3(transform.GetChild(i).localScale.x *scale, transform.GetChild(i).localScale.y, transform.GetChild(i).localScale.z *scale); transform.GetChild(i).eulerAngles = new Vector3(Random.Range(-10, 10), Random.Range(-10, 10), Random.Range(-10, 10)); } }
private void Awake() { damagerR = AttackR.GetComponent <DamagerScript>(); damagerL = AttackL.GetComponent <DamagerScript>(); damagerR2 = AttackR2.GetComponent <DamagerScript>(); damagerL2 = AttackL2.GetComponent <DamagerScript>(); attackR = AttackR.GetComponent <TemporalEnablerScript>(); attackL = AttackL.GetComponent <TemporalEnablerScript>(); attackR2 = AttackR2.GetComponent <TemporalEnablerScript>(); attackL2 = AttackL2.GetComponent <TemporalEnablerScript>(); hii = SelectedItemDisplay.GetComponent <HeldItemImage>(); cc2 = GetComponent <CapsuleCollider2D>(); renderer = GetComponent <SpriteRenderer>(); rigidbody2D = GetComponent <Rigidbody2D>(); animator = GetComponent <Animator>(); inventory = GetComponent <PlayerInventoryScript>(); hps = GetComponent <HealthPointsScript>(); cam = Camera.GetComponent <Camera>(); pes = GetComponent <PotionEffectsScript>(); throwers.Clear(); throwers.Add("BOMB", Thrower_Bomb.GetComponent <PlayerThrowScript>()); throwers.Add("AF_P", Thrower_AF_P.GetComponent <PlayerThrowScript>()); throwers.Add("AF_M", Thrower_AF_M.GetComponent <PlayerThrowScript>()); throwers.Add("AF_F", Thrower_AF_F.GetComponent <PlayerThrowScript>()); throwers.Add("AF_A", Thrower_AF_A.GetComponent <PlayerThrowScript>()); throwers.Add("AF_H", Thrower_AF_H.GetComponent <PlayerThrowScript>()); throwers.Add("PT_V", Thrower_PT_V.GetComponent <PlayerThrowScript>()); throwers.Add("AR_R", Thrower_AR_R.GetComponent <PlayerThrowScript>()); throwers.Add("AR_H", Thrower_AR_H.GetComponent <PlayerThrowScript>()); throwers.Add("AR_F", Thrower_AR_F.GetComponent <PlayerThrowScript>()); throwers.Add("AR_P", Thrower_AR_P.GetComponent <PlayerThrowScript>()); throwers.Add("AR_M", Thrower_AR_M.GetComponent <PlayerThrowScript>()); GroundCheck1 = GroundCheck + new Vector2(0.15f, 0f); GroundCheck2 = GroundCheck + new Vector2(-0.15f, 0f); //GOD MODE if (GodMode) { hps.IncreaseMax(100000); dmgMult = 10000; IncreaseAttackMult(); } }
void Start() { soundEffects = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>(); // Since there will only be 1 inventory at any point of time if (playerInventory == null) { playerInventory = FindObjectOfType <PlayerInventoryScript>(); } if (theItemStuff == null) { theItemStuff = GetComponent <ItemScript>(); } if (itemInteractParticles == null) { itemInteractParticles = GameObject.Find(m_ParticleSystemName).GetComponent <ParticleScript>(); } }
public Player( GameObject gameObject, PlayerMovementScript movementScript, PlayerLookScript lookScript, PlayerInventoryScript inventoryScript, PlayerBlockInteractionScript blockInteractionScript ) { this.gameObject = gameObject; this.movementScript = movementScript; this.lookScript = lookScript; this.inventoryScript = inventoryScript; this.blockInteractionScript = blockInteractionScript; this.movementScript.SetSelfPlayer(this); this.lookScript.SetSelfPlayer(this); this.inventoryScript.SetSelfPlayer(this); this.blockInteractionScript.SetSelfPlayer(this); }
/// <summary> /// Used to save data based on the m_loadNumber! /// </summary> public void saveData() { // If it is not within the save file, dont save! if (m_loadNumber > 3 || m_loadNumber <= 0) { return; } // We will go get the player's control and player's current health so that we can save the health and what items the player is carrying! GameObject zePlayerController = GameObject.FindGameObjectWithTag("GameController"); GameObject zePlayer = GameObject.FindGameObjectWithTag("Player"); // Need to make sure the object exists otherwise it is meaningless! if (zePlayer != null && zePlayerController != null) { // Here is where we save the player's health List <string> zeCondtions = new List <string>(); zeCondtions.Add("PlayerID = " + m_loadNumber); // Based on the m_loadNumber, we will save the data to there as player's ID! HealthScript zePlayerHealth = zePlayer.GetComponent <HealthScript>(); MySQLiteHandler.instance.saveSpecificResult(PersistentHealthScript.playerTableName, "PlayerHealth", zePlayerHealth.m_health.ToString(), zeCondtions); MySQLiteHandler.instance.saveSpecificResult(PersistentHealthScript.playerTableName, "PlayerMaxHealth", zePlayerHealth.max_health.ToString(), zeCondtions); // Followed by the Player's inventory! PlayerInventoryScript zePlayerStuff = zePlayerController.GetComponent <PlayerInventoryScript>(); // We shall then iterate through the itemlist and see if there is any item to be saved! foreach (KeyValuePair <string, itemInformation> zeItemNameAndInform in zePlayerStuff.itemName_Count_Map) { zeCondtions.Clear(); Debug.Log("PlayerID = " + m_loadNumber); Debug.Log("ItemName = " + zeItemNameAndInform.Key); Debug.Log("ItemCount = " + zeItemNameAndInform.Value.item_count); zeCondtions.Add("PlayerID = " + m_loadNumber); zeCondtions.Add("ItemName = " + MySQLiteHandler.instance.helpToConvertToSQLString(zeItemNameAndInform.Key)); MySQLiteHandler.instance.saveSpecificResult(zePlayerStuff.PlayerInventoryTable, "ItemCount", zeItemNameAndInform.Value.item_count.ToString(), zeCondtions); } // Finally, we will save the scene index to the SQLite zeCondtions.Clear(); zeCondtions.Add("PlayerID = " + m_loadNumber); MySQLiteHandler.instance.saveSpecificResult(PersistentHealthScript.playerTableName, m_SceneIndexField, SceneManager.GetActiveScene().buildIndex.ToString(), zeCondtions); } }
// Using this function will allows the restart of finding item in the inventory again! void OnEnable() { if (playerInventory == null) { playerInventory = FindObjectOfType <PlayerInventoryScript>(); } //Debug.Log("Gonna insert items into the UI: " + playerInventory.itemName_Count_Map.Count); // Trying to get the key and value then put it in the slot! foreach (KeyValuePair <string, itemInformation> zeNameAndItem in playerInventory.itemName_Count_Map) { //Debug.Log("Trying to insert items into the UI"); // Need to make sure that the items count are more than 0! if (zeNameAndItem.Value.item_count > 0) { GameObject zeItemUI = null; foreach (GameObject zeGO in allItemPrefabs) { zeItemUI = Instantiate(zeGO); zeItemUI.BroadcastMessage("Start"); // Need to initialize the gameobject ItemScript zeItemInform = zeItemUI.GetComponentInChildren <ItemScript>(); //Debug.Log("The GO: " + zeItemUI.name); //Debug.Log("The item's name: " + zeNameAndItem.Value.item_name); //Debug.Log("GO item's inform: " + zeItemInform.m_itemInform.item_name); if (zeItemInform.m_itemInform.item_name.Equals(zeNameAndItem.Value.item_name)) { // We will make a copy of the item! break; } else { DestroyObject(zeItemUI); } } //allTheSlots[m_AvailableSlots].transform.A; //Debug.Log("The Items: " + zeItemUI.name); zeItemUI.GetComponent <RectTransform>().SetParent(allTheSlots[m_AvailableSlots].GetComponent <RectTransform>(), false); ++m_AvailableSlots; } } }
void Update() { if (firstFrame) { firstFrame = false; while (true) { bool hasThing = false; Collider[] colls = Physics.OverlapBox(transform.position, new Vector3(1, 2, 1)); foreach (Collider i in colls) { if (i.gameObject.GetComponent <TerrainScript> () != null && i.gameObject.GetComponent <TerrainScript>().terrainName == "water") { hasThing = true; break; } } if (!hasThing) { break; } else { transform.Translate(1, 0, 0); } } } if (sleeping) { if (Time.timeScale != 10) { Time.timeScale = 10; } energy += Time.deltaTime / 2; if (energy >= maxEnergy - 1) { toggleSleep(sleepText); } } else if (Time.timeScale != 1) { Time.timeScale = 1; } //lose hunger, update hunger bar if (hunger > maxHunger) { hunger = maxHunger; } if (health > maxHealth) { health = maxHealth; } if (happiness > maxHappiness) { happiness = maxHappiness; } if (energy > maxEnergy) { energy = maxEnergy; } if (hunger > 0) { if (working) { hunger -= Time.deltaTime / 2.5f; } else { hunger -= Time.deltaTime / 6f; } } else if (health > 0) { health -= Time.deltaTime * 2; } else { //die } if (energy > 0) { if (working) { energy -= Time.deltaTime / 1.5f; } else { energy -= Time.deltaTime / 4; } } else if (health > 0) { health -= Time.deltaTime / 3f; } else { //die } hungerBar.transform.localScale = new Vector3(hungerBar.transform.localScale.x, hungerBar.transform.localScale.x * (hunger / maxHunger), hungerBar.transform.localScale.z); healthBar.transform.localScale = new Vector3(healthBar.transform.localScale.x, healthBar.transform.localScale.x * (health / maxHealth), healthBar.transform.localScale.z); energyBar.transform.localScale = new Vector3(energyBar.transform.localScale.x, energyBar.transform.localScale.x * (energy / maxEnergy), energyBar.transform.localScale.z); //check tools PlayerInventoryScript s = GetComponent <PlayerInventoryScript> (); rightArmRotationEuler = rightArm.transform.eulerAngles.x; if (prevPos != transform.position) { updateCamera(); prevPos = transform.position; } if (!equipTool && s.determineWhetherItemIsToolWithName(s.playerInventory[s.playerInventory.Length - 1].name) && s.playerInventory[s.playerInventory.Length - 1].quantity > 0) { changeEquipTool(true, s.playerInventory[s.playerInventory.Length - 1].name); } else if (equipTool && (!s.determineWhetherItemIsToolWithName(s.playerInventory[s.playerInventory.Length - 1].name) || s.playerInventory[s.playerInventory.Length - 1].quantity <= 0)) { changeEquipTool(false, s.playerInventory[s.playerInventory.Length - 1].name); } //construction if (s.determineWhetherItemIsBuildingWithName(s.playerInventory [s.playerInventory.Length - 1].name) && constructionHover == null) { GameObject buildPrefab = s.findBuildingPrefabWithName(s.playerInventory [s.playerInventory.Length - 1].name); GameObject insItem = Instantiate(constructionHoverPrefab, new Vector3(transform.position.x, -0.5f, transform.position.z), transform.rotation); constructionHover = insItem; constructionHover.transform.localScale = new Vector3(buildPrefab.GetComponent <BoxCollider>().size.x, 1, buildPrefab.GetComponent <BoxCollider>().size.z); updateConstructionHover(); } if (!s.determineWhetherItemIsBuildingWithName(s.playerInventory [s.playerInventory.Length - 1].name) || s.playerInventory [s.playerInventory.Length - 1].quantity <= 0) { if (constructionHover != null) { Destroy(constructionHover); constructionHover = null; updateConstructionHover(); } } //builds the building here; refer back when creating save method if (working && canBuildBuilding && constructionHover != null) { GameObject insItem = Instantiate(s.findBuildingPrefabWithName(s.playerInventory [s.playerInventory.Length - 1].name), new Vector3(constructionHover.transform.position.x, s.findBuildingPrefabWithName(s.playerInventory [s.playerInventory.Length - 1].name).transform.position.y, constructionHover.transform.position.z), constructionHover.transform.rotation); GetComponent <PlayerInventoryScript> ().addGameObjectToSaves(insItem); s.playerInventory [s.playerInventory.Length - 1].quantity--; s.updateAllSprites(); } Rect rect = new Rect(new Vector2(workButton.GetComponent <RectTransform> ().position.x - workButton.GetComponent <RectTransform> ().rect.size.x / 2, workButton.GetComponent <RectTransform> ().position.y - workButton.GetComponent <RectTransform> ().rect.size.y / 2), workButton.GetComponent <RectTransform> ().rect.size); if (rect.Contains(Input.mousePosition) && Input.GetMouseButton(0) || Input.GetKey(KeyCode.G)) { working = true; } else { working = false; } //check fps checkInterval -= Time.deltaTime; if (checkInterval <= 0) { checkInterval = 1; framesPerSecond = 1 / Time.deltaTime; } //determine swing animation if (!sleeping) { if (prevWorking && !working) { rightArmStop = true; } if (rightArmStop && (leftArm.transform.eulerAngles.x > 350 + framesPerSecond / 10 || leftArm.transform.eulerAngles.x < 10 - framesPerSecond / 10) && (rightArm.transform.eulerAngles.x > 350 + framesPerSecond / 10 || rightArm.transform.eulerAngles.x < 10 - framesPerSecond / 10)) { rightArmStop = false; } if (working) { moving = false; if (swingRightWork) { rightArm.transform.Rotate(new Vector3(-Time.deltaTime * 180, 0, 0), Space.Self); } else { rightArm.transform.Rotate(new Vector3(Time.deltaTime * 360, 0, 0), Space.Self); } } if (!working && (equipTool || !moving || masterControllerScript.touchContainsUI || masterControllerScript.UIBusy || rightArmStop)) { if (rightArm.transform.eulerAngles.x < 350 + (framesPerSecond / 10) && rightArm.transform.eulerAngles.x > 200) { rightArm.transform.Rotate(new Vector3(Time.deltaTime * 170, 0, 0), Space.Self); } if (rightArm.transform.eulerAngles.x > 10 - (framesPerSecond / 10) && rightArm.transform.eulerAngles.x < 100) { rightArm.transform.Rotate(new Vector3(-Time.deltaTime * 170, 0, 0), Space.Self); } } if (moving && !masterControllerScript.touchContainsUI && !masterControllerScript.UIBusy) { if (swingRightMove) { if (!equipTool && !rightArmStop) { rightArm.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } leftArm.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); rightLeg.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); leftLeg.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } else { if (!equipTool && !rightArmStop) { rightArm.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } leftArm.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); rightLeg.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); leftLeg.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } } else { if (leftLeg.transform.eulerAngles.x < 350 + (framesPerSecond / 10) && leftLeg.transform.eulerAngles.x > 200) { if (!working && !equipTool && !rightArmStop) { rightArm.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } leftArm.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); rightLeg.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); leftLeg.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } else if (leftLeg.transform.eulerAngles.x > 10 - (framesPerSecond / 10) && leftLeg.transform.eulerAngles.x < 100) { if (!working && !equipTool && !rightArmStop) { rightArm.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } leftArm.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); rightLeg.transform.Rotate(new Vector3(Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); leftLeg.transform.Rotate(new Vector3(-Time.deltaTime * 54 * moveSpeed, 0, 0), Space.Self); } } //determine swing direction if (leftLeg.transform.eulerAngles.x < 330 && leftLeg.transform.eulerAngles.x > 200 && swingRightMove) { swingRightMove = false; } if (leftLeg.transform.eulerAngles.x > 30 && leftLeg.transform.eulerAngles.x < 100 && !swingRightMove) { swingRightMove = true; } if (rightArm.transform.eulerAngles.x < 330 && rightArm.transform.eulerAngles.x > 200 && swingRightMove) { swingRightMove = false; } if (rightArm.transform.eulerAngles.x > 30 && rightArm.transform.eulerAngles.x < 100 && !swingRightMove) { swingRightMove = true; } if (working) { if (rightArm.transform.eulerAngles.x < 290 && rightArm.transform.eulerAngles.x > 250 && swingRightWork) { swingRightWork = false; if (prevSwingRight) { if (equipTool) { rightArm.transform.GetChild(0).GetChild(0).GetComponent <ToolScript> ().doDamage = true; } transform.Translate(Vector3.forward, Space.Self); Collider[] coll = Physics.OverlapSphere(transform.position, 0.8f); transform.Translate(Vector3.back, Space.Self); if (coll.Length > 0) { foreach (Collider i in coll) { if (i.GetComponent <GrassScript> () != null) { i.GetComponent <GrassScript> ().harvestItem(); } else if (i.GetComponent <BushScript> () != null) { i.GetComponent <BushScript> ().harvestItem(); } else if (i.GetComponent <BerryBushScript> () != null) { i.GetComponent <BerryBushScript> ().harvestItem(); } else if (i.GetComponent <GroundFoodScript> () != null) { i.GetComponent <GroundFoodScript> ().harvestItem(); } } } } prevSwingRight = false; } if (rightArm.transform.eulerAngles.x > 30 && rightArm.transform.eulerAngles.x < 100 && !swingRightWork) { swingRightWork = true; prevSwingRight = true; } } prevWorking = working; } }
void Start() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript>(); originalMaterialColour = GetComponent <Renderer> ().material.color; }
void Update() { rect = new Rect(new Vector2(GetComponent <RectTransform>().position.x - GetComponent <RectTransform>().rect.width / 2, GetComponent <RectTransform>().position.y - GetComponent <RectTransform>().rect.height / 2), new Vector2(GetComponent <RectTransform>().rect.width, GetComponent <RectTransform>().rect.height)); parentRect = new Rect(new Vector2(transform.parent.GetComponent <RectTransform>().position.x - transform.parent.GetComponent <RectTransform>().rect.width / 2, transform.parent.GetComponent <RectTransform>().position.y - transform.parent.GetComponent <RectTransform>().rect.height / 2), new Vector2(transform.parent.GetComponent <RectTransform>().rect.width, transform.parent.GetComponent <RectTransform>().rect.height)); if ((isFood() || isFuel()) && playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity > 0) { if (clickedOnce) { if (isFood() && transform.GetChild(0).gameObject.GetComponent <Text> ().text != "Eat") { transform.GetChild(0).gameObject.GetComponent <Text> ().text = "Eat"; } if (isFuel() && transform.GetChild(0).gameObject.GetComponent <Text> ().text != "Add" && closeToFire(2) != null) { transform.GetChild(0).gameObject.GetComponent <Text> ().text = "Add"; } clickedTimer -= Time.deltaTime; if (clickedTimer <= 0) { clickedOnce = false; updateSprite(); } } if (Input.GetMouseButtonUp(0) && rect.Contains(new Vector2(Input.mousePosition.x, Input.mousePosition.y)) && parentRect.Contains(new Vector2(Input.mousePosition.x, Input.mousePosition.y))) { if (!clickedOnce) { clickedOnce = true; clickedTimer = 2; } else if (isFood()) { masterControllerScript.playerInventoryScript.GetComponent <PlayerScript> ().hunger += masterControllerScript.playerInventoryScript.findFoodValuesWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name).hunger; masterControllerScript.playerInventoryScript.GetComponent <PlayerScript> ().health += masterControllerScript.playerInventoryScript.findFoodValuesWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name).health; masterControllerScript.playerInventoryScript.GetComponent <PlayerScript> ().happiness += masterControllerScript.playerInventoryScript.findFoodValuesWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name).happiness; playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity--; updateSprite(); } else if (isFuel()) { if (closeToFire(2) != null) { playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity--; closeToFire(2).GetComponent <FireScript> ().fuel += masterControllerScript.playerInventoryScript.findFuelValuesWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name).fuelValue; updateSprite(); } } } } if (transform.localPosition != Vector3.zero && !followMouse) { transform.localPosition = Vector3.zero; } if (Input.GetMouseButtonDown(0) && rect.Contains(Input.mousePosition) && GetComponent <Image> ().enabled) { followMouse = true; } if (followMouse) { if (transform.parent.parent != GameObject.Find("Front").transform) { transform.parent.SetParent(GameObject.Find("Front").transform); } transform.position = Input.mousePosition; masterControllerScript.UIBusy = true; } else { if (transform.parent.parent != GameObject.Find("Back").transform) { transform.parent.SetParent(GameObject.Find("Back").transform); } } if (Input.GetMouseButtonUp(0) && followMouse) { masterControllerScript.UIBusy = false; followMouse = false; transform.position = previousPosition; bool change = false; GameObject swapGameObject = null; float distance = 1000; int a = 0; foreach (Rect i in masterControllerScript.inventoryUI) { if (i.Overlaps(rect) && i != new Rect(0, 0, 0, 0) && Vector2.Distance(new Vector2(i.x, i.y), new Vector2(rect.x, rect.y)) < distance) { swapGameObject = masterControllerScript.inventoryUIObject[a].transform.GetChild(0).gameObject; GetComponent <RectTransform>().position = new Vector2(i.x + i.width / 2, i.y + i.height / 2); distance = Vector2.Distance(new Vector2(i.x, i.y), new Vector2(rect.x, rect.y)); change = true; } a++; } if (change && swapGameObject != gameObject && (swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex != 12 || masterControllerScript.playerInventoryScript.determineWhetherItemIsToolWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name) || masterControllerScript.playerInventoryScript.determineWhetherItemIsBuildingWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name))) { if (playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name == playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name) { if (playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity + playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity <= masterControllerScript.playerInventoryScript.findItemStackCapacityWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name)) { playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity = playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity + playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity; playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity = 0; } else { int val = masterControllerScript.playerInventoryScript.findItemStackCapacityWithName(playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name); playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity = playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity + playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity - masterControllerScript.playerInventoryScript.findItemStackCapacityWithName(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name); playerInv [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity = val; } } else { InventoryItem intersectStorage = masterControllerScript.playerInventoryScript.playerInventory [transform.parent.GetComponent <InventoryUIScript> ().rectIndex]; masterControllerScript.playerInventoryScript.playerInventory [transform.parent.GetComponent <InventoryUIScript> ().rectIndex] = masterControllerScript.playerInventoryScript.playerInventory [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex]; masterControllerScript.playerInventoryScript.playerInventory [swapGameObject.transform.parent.GetComponent <InventoryUIScript> ().rectIndex] = intersectStorage; } Transform target = swapGameObject.transform.parent; swapGameObject.transform.SetParent(transform.parent); transform.SetParent(target); GetComponent <RectTransform> ().localPosition = Vector3.zero; swapGameObject.GetComponent <RectTransform> ().localPosition = Vector3.zero; previousPosition = transform.position; swapGameObject.GetComponent <InventoryItemScript> ().previousPosition = swapGameObject.transform.position; updateSprite(); swapGameObject.GetComponent <InventoryItemScript> ().updateSprite(); } else if (swapGameObject != gameObject) { PlayerInventoryScript script = masterControllerScript.playerInventoryScript; GameObject insItem = Instantiate(script.droppedItemPrefab, new Vector3(script.transform.position.x, -0.7f, script.transform.position.z), script.droppedItemPrefab.transform.rotation); insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity, playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].name, playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].displayName); masterControllerScript.playerInventoryScript.addDroppedItemToSaves(insItem); playerInv [transform.parent.GetComponent <InventoryUIScript> ().rectIndex].quantity = 0; updateSprite(); } else { transform.position = previousPosition; } if (masterControllerScript.playerInventoryScript.determineWhetherItemIsToolWithName(playerInv[12].name) && playerInv[12].quantity > 0) { GameObject.Find("Player").GetComponent <PlayerScript> ().changeEquipTool(true, playerInv[12].name); } } }
void Start() { playerScript = GameObject.Find("Player").GetComponent <PlayerScript> (); playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> (); }
void Start() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> (); updateImage(true); }
void Awake() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> (); if (PlayerPrefs.GetInt("saveGame") != 1) { //generate stuff on terrain Vector3 offset = transform.position; for (float i = -3 + (int)offset.x; i < 4 + (int)offset.x; i += 2) { for (float j = -3 + (int)offset.z; j < 4 + (int)offset.z; j += 2) { float rand = Random.Range(0f, 100f); if (rand < spawnTreesPercentage) { //spawn trees GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("tree"), new Vector3(i, -1, j), Quaternion.identity); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnFlintPercentage + spawnTreesPercentage) { //spawn flint GameObject insItem = Instantiate(droppedItemPrefab, new Vector3(i, -0.7f, j), droppedItemPrefab.transform.rotation) as GameObject; insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "flint", "Flint"); playerInventoryScript.addDroppedItemToSaves(insItem); } else if (rand < spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage) { //spawn grass GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("grassPatch"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage) { //spawn bush GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("bush"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage) { //spawn berry bush GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("berryBush"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage) { //spawn boulder GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("boulder"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("boulder").transform.rotation); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage) { //spawn carrot GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("naturalCarrot"), new Vector3(i + Random.Range(-0.5f, 0.5f), -0.9f, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("naturalCarrot").transform.rotation); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage) { //spawn tomato GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("naturalTomato"), new Vector3(i + Random.Range(-0.5f, 0.5f), -0.9f, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("naturalTomato").transform.rotation); playerInventoryScript.addGameObjectToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage + spawnSheepPercentage) { //spawn sheep GameObject insItem = Instantiate(playerInventoryScript.findMobPrefabWithName("sheep"), new Vector3(i, -0.2f, j), Quaternion.identity); playerInventoryScript.addMobToSaves(insItem); } else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage + spawnSheepPercentage + spawnPigPercentage) { //spawn pig GameObject insItem = Instantiate(playerInventoryScript.findMobPrefabWithName("pig"), new Vector3(i, -0.2f, j), Quaternion.identity); playerInventoryScript.addMobToSaves(insItem); } } } } }
void Start() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript>(); originalMaterialColour1 = transform.GetChild(0).GetComponent <Renderer> ().material.color; originalMaterialColour2 = transform.GetChild(1).GetComponent <Renderer> ().material.color; }
void Start() { player = GameObject.Find("Player"); playerInventoryScript = player.GetComponent <PlayerInventoryScript> (); GetComponent <Image> ().sprite = playerInventoryScript.findItemSpriteWithName(myValue.name); }
// Start is called before the first frame update void Start() { inventory = Player.GetComponent <PlayerInventoryScript>(); image = GetComponent <Image>(); }
void Awake() { playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> (); daylightCycleClock = new int[][][] { //fall new int[][] { new int[] { 9, 3, 2, 2 }, new int[] { 9, 3, 2, 2 }, new int[] { 9, 3, 2, 2 }, new int[] { 8, 3, 2, 3 }, new int[] { 8, 3, 2, 3 }, new int[] { 7, 4, 2, 3 }, new int[] { 7, 4, 2, 3 }, new int[] { 6, 4, 3, 3 }, new int[] { 6, 4, 3, 3 }, new int[] { 5, 4, 4, 3 } }, //winter new int[][] { new int[] { 5, 4, 4, 3 }, new int[] { 5, 3, 5, 3 }, new int[] { 5, 3, 5, 3 }, new int[] { 4, 4, 5, 3 }, new int[] { 4, 3, 6, 3 }, new int[] { 4, 3, 6, 3 }, new int[] { 3, 4, 6, 3 }, new int[] { 3, 4, 5, 4 }, new int[] { 4, 3, 5, 4 }, new int[] { 4, 4, 4, 4 } }, //spring new int[][] { new int[] { 5, 4, 4, 3 }, new int[] { 5, 5, 3, 3 }, new int[] { 5, 5, 3, 3 }, new int[] { 6, 4, 3, 3 }, new int[] { 6, 4, 3, 3 }, new int[] { 6, 3, 3, 4 }, new int[] { 6, 3, 3, 4 }, new int[] { 7, 3, 3, 3 }, new int[] { 7, 4, 3, 3 }, new int[] { 8, 3, 2, 3 } }, //summer new int[][] { new int[] { 8, 2, 2, 4 }, new int[] { 9, 2, 2, 3 }, new int[] { 10, 2, 2, 2 }, new int[] { 11, 2, 1, 2 }, new int[] { 12, 1, 1, 2 }, new int[] { 12, 1, 1, 2 }, new int[] { 12, 1, 2, 1 }, new int[] { 11, 2, 2, 1 }, new int[] { 10, 2, 2, 2 }, new int[] { 9, 3, 2, 2 } } }; if (PlayerPrefs.GetInt("saveGame") == 0) { newDay(); } }