Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

MrGohut

Member
  • Content Count

    24
  • Joined

  • Last visited

Community Reputation

0 Neutral

About MrGohut

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Location:
    Poland, Lodz
  1. ehh no, i didn't say that i made it. I used tutorial for this, because i can't learn from wall of text >.< I need to do something and then, when i have it i can read it and understand it.
  2. Ymmm nope. I have this system, i need to do STACKABLE items just it, not whole inv system. Guys, stacks just stack not 2 slots per item or something else. Idk, like .. hmmm like potions in RPG
  3. But guys i need to do STACKABLE inv. In need help with this not with if / else or mathf :< Look at this vid: http://youtu.be/qllmauY_yjo And that's it: It add new item even if it is in inventory but in the next slot. I need to loop and search for this item in my inventory and then add stacks to it only not creating new item. If my item reach maxAmount i need to stop adding stack to this item and create new one and add stack to this new one. Second thing is when i modify variables in my inventory it change in itemdatabase too and i think that's the problem but i dont know how can i fix it. Now u know what i mean ? This is my AddItem function: void AddItem(int id, int Amount) { for(int i = 0; i < inventory.Count; i++) //Looping all slots { if(inventory[i].itemName == null) //if empty slot { Debug.Log("Free slot founded !"); for(int d = 0; d < database.items.Count; d++) //search for item in database { if(database.items[d].itemID == id) //if ID from AddItem() = ID in database { //ADD ITEM //?!?!?!?! inventory[i] = database.items[d];// <----- old lane inventory[i].AmountNow += Amount; } } break; //STOP. } if(inventory[i].itemID == id) { inventory[i].AmountNow += Amount; break; } } }
  4. Hi I paste here my scripts Inventory.cs using UnityEngine; using System.Collections; using System.Collections.Generic; public class Inventory : MonoBehaviour { public SimpleMouseRotator camera1; public SimpleMouseRotator camera2; public int slotsX, slotsY; public GUISkin skin; public List<Item> inventory = new List<Item>(); public List<Item> slots = new List<Item>(); public bool showInventory; private bool showTooltip; private bool draggingItem; private Item draggedItem; private string tooltip; private ItemDatabase database; private int prevIndex; void Start() { camera1 = GameObject.FindWithTag("Player").GetComponent<SimpleMouseRotator>(); camera2 = GameObject.FindWithTag("MainCamera").GetComponent<SimpleMouseRotator>(); database = GameObject.FindGameObjectWithTag("ItemDatabase").GetComponent<ItemDatabase>(); for(int i = 0; i < (slotsX * slotsY); i++) { slots.Add(new Item()); inventory.Add(new Item()); } AddItem(1, 10); AddItem(2, 10); AddItem(3, 1); } void Update() { if(Input.GetKeyDown(KeyCode.Y)) { AddItem(3, 1); } if(Input.GetKey(KeyCode.U)) { AddItem(3, 1); } if(Input.GetKeyDown(KeyCode.Tab)) { showInventory = !showInventory; } if(showInventory) { camera1.enabled = false; camera2.enabled = false; } else { camera1.enabled = true; camera2.enabled = true; } } void OnGUI() { tooltip = ""; GUI.skin = skin; if(showInventory) { DrawInventory(); if(showTooltip) GUI.Box(new Rect(Event.current.mousePosition.x + 15f, Event.current.mousePosition.y, 200, 200), tooltip, skin.GetStyle("Tooltip")); } if(draggingItem) { GUI.DrawTexture(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 50, 50), draggedItem.itemIcon); } } void DrawInventory() { Event e = Event.current; int i = 0; for(int y = 0; y < slotsY; y++) { for(int x = 0; x < slotsX; x++) { Rect slotRect = new Rect(x * 60, y * 60, 50, 50); GUI.Box(slotRect, "", skin.GetStyle("Slots")); slots[i] = inventory[i]; int itemAmount = inventory[i].AmountNow; if(slotRect.Contains(e.mousePosition)) { if(e.type == EventType.mouseDown) { print("Clicked slot: " + slots[i].itemID); } } if(slots[i].itemName != null) { GUI.DrawTexture(slotRect, slots[i].itemIcon); GUI.Label(new Rect(x * 60,y * 60,50,50), itemAmount.ToString()); if(slotRect.Contains(e.mousePosition)) { tooltip = CreateTooltip(slots[i]); showTooltip = true; //przenoszenie przedmiotów - podnieś if(e.button == 0 && e.type == EventType.mouseDrag && !draggingItem) { draggingItem = true; prevIndex = i; draggedItem = slots[i]; inventory[i] = new Item(); } //przenoszenie przedmiotów - upuść if(e.type == EventType.mouseUp && draggingItem) { inventory[prevIndex] = inventory[i]; inventory[i] = draggedItem; draggingItem = false; draggedItem = null; } //Używanie przedmiotów if(e.isMouse && e.type == EventType.mouseDown && e.button == 1) { print("Clicked " + i); if(inventory[i].itemType == Item.ItemType.Consumable) { if(itemAmount == 1) { UseConsumable(slots[i], i, true, false); } else { UseConsumable(slots[i], i, false, true); } } } } } else { if(slotRect.Contains(e.mousePosition)) { if(e.type == EventType.mouseUp && draggingItem) { inventory[i] = draggedItem; draggingItem = false; draggedItem = null; } } } if(tooltip == "") { showTooltip = false; } i++; } } } //wyświetlanie opisu przedmiotu po najechaniu na niego myszką string CreateTooltip(Item item) { tooltip = "<color=#ffffff>" + item.itemName + "</color>\n\n" + item.itemDesc; return tooltip; } void RemoveItem(int id) { for(int i = 0; i < inventory.Count; i++) { if(inventory[i].itemID == id) { inventory[i] = new Item(); break; } } } void AddItem(int id, int Amount) { for(int i = 0; i < inventory.Count; i++) { if(inventory[i].itemName == null) { for(int d = 0; d < database.items.Count; d++) { if(database.items[d].itemID == id) { inventory[i] = database.items[d]; if(inventory[i].AmountNow != inventory[i].maxAmount) { inventory[i].AmountNow += Amount; } else break; } } break; } /*/Jeżeli nie istnieje, dodaj item if(inventory[i].itemName == null) { for(int j = 0; j < database.items.Count; j++) { if(database.items[j].itemID == id) { inventory[i] = database.items[j]; inventory[i].AmountNow = 1; } } break; }*/ } } /* void AddItemCount(int id) { for(int i = 0; i < inventory.Count; i++) { if(inventory[i].itemName != null) { inventory[i].itemCount += 1; break; } } } */ bool InventoryContains(int id){ foreach(Item item in inventory){ if(item.itemID == id) return true; } return false; } //Używanie itemów private void UseConsumable(Item item, int slot, bool deleteItem, bool deleteCount) { //switch (zostawić) switch(item.itemID) { //case id, np. jabłko ma id 4 -> case 4: .... coś zrób case 2: { print("Mnom, mnom, mnom"); break; } } //jeżeli wysłana informacja o usunięciu if(deleteItem) inventory[slot] = new Item(); //jeżeli wysłana informacja o zmianie licznika if(deleteCount) { for(int i = 0; i < inventory.Count; i++) { if(inventory[i].itemID == item.itemID) { inventory[i].AmountNow -= 1; break; } } } } } Item.cs using UnityEngine; using System.Collections; [System.Serializable] public class Item { public string itemName; public int itemID; public string itemDesc; public Texture2D itemIcon; public int maxAmount; public int AmountNow; public ItemType itemType; public enum ItemType { Weapon, Consumable, Resource } public Item(string name, int id, string desc, int maxAm, int Amount, ItemType type) { itemName = name; itemID = id; itemDesc = desc; itemIcon = Resources.Load<Texture2D>("ItemIcons/" + name); maxAmount = maxAm; AmountNow = Amount; itemType = type; } public Item() { } } ItemDatabase.cs using UnityEngine; using System.Collections; using System.Collections.Generic; public class ItemDatabase : MonoBehaviour { public List<Item> items = new List<Item>(); void Start() { items.Add(new Item("Stone", 1, "Stone.", 10, 0, Item.ItemType.Resource)); items.Add(new Item("Wood", 2, "Wood.", 10, 0, Item.ItemType.Resource)); items.Add(new Item("Berry", 3, "Berry.", 10, 0, Item.ItemType.Consumable)); } } And i need to do stackable items. I got it at half, but i need to set max amount per slot. Now, my "Berry" have max 10 stacks, it start from 1 but when i hit Y to add stacks to Berry it add it, but also next berry in next slot. When berry reach 10 it add all the time this item to next slots. You can try it by yourself. I need to do a stackable items, can someone help me with this ? ;/
  5. Yes yes, i know tagging etc but when i used mass place tree i couldnt set tags or layers ;p now i place trees manually. Thanks for help (link) ! P.S. (sorry for my eng)
  6. And if i place my trees i need to add billboarding, where can i find this ?
  7. Hmm i know its better but .. i have so big terrain D: GOD D: hmm so propably i must place it manually ;(
  8. So.. i need to check if my RayCast hitted the tree, but i cant do this because trees are placed by "mass tree" option in the terrain options. I can't set tag or layer for them, so how can i do this ?
  9. Nvm i added this: if(Active) { newCube.transform.position = transform.position + transform.forward * 4.0f; } but thats strange, because when i had Character from Standard Asstes (basic import character) everything worked fine with this script o.O
  10. using UnityEngine; using System.Collections; public class Build : MonoBehaviour { public GameObject cube1; public GameObject cube2; public GameObject cube3; public GameObject cube4; public bool Cube1; public bool Cube2; public bool Cube3; public bool Cube4; public bool block; private GameObject newCube; public bool Active; public bool warning; public bool clear; public Inventory check; public string warningText; void Start () { } void Update () { if(Input.GetKeyDown(KeyCode. && !Active && !block) { if(check.woodCount > 0) { if(Cube1) { newCube = Instantiate(cube1, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject; Active = true; newCube.transform.parent = Camera.main.transform; //check.woodCount -= 10; //cube.rigidbody.isKinematic = true; block = true; } if(Cube2) { newCube = Instantiate(cube2, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject; Active = true; newCube.transform.parent = Camera.main.transform; //check.woodCount -= 10; //cube.rigidbody.isKinematic = true; block = true; } if(Cube3) { newCube = Instantiate(cube3, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject; Active = true; newCube.transform.parent = Camera.main.transform; //check.woodCount -= 10; //cube.rigidbody.isKinematic = true; block = true; } if(Cube4) { newCube = Instantiate(cube4, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject; Active = true; newCube.transform.parent = Camera.main.transform; //check.woodCount -= 10; //cube.rigidbody.isKinematic = true; block = true; } } else { warningText = "You don't have wood !"; warning = true; } } if(Input.GetKeyDown(KeyCode.V) && Active && block) { newCube.transform.parent = null; //cube.rigidbody.isKinematic = false; Active = false; clear = true; block = false; } if(clear) { Cube1 = false; Cube2 = false; Cube3 = false; Cube4 = false; clear = false; } } } My problem: I can spawn cube, it spawn in fron of me, 10 forward like in script, but after that when i move my character, cube doesn't follow ;/ it just rotate with me, nothnig else. I have First Person Character from Sample Asstes .
  11. Somethnig was wrong with this script. I downloaded Sample Assets from asste store and i did it finally.
  12. So how D: using UnityEngine; using System.Collections; public class UI : MonoBehaviour { public Transform cam; public Build build; public Health health; public Hunger hunger; public Inventory item; public Rect healthpos; public Rect hungerpos; public Rect woodpos; public Rect cube1pos; public Rect cube2pos; public Rect cube3pos; public Rect cube4pos; public Rect warningPos; public bool chooseStructure; void Start() { } void Update() { if(Input.GetKeyDown(KeyCode.E)) { chooseStructure = !chooseStructure; if(chooseStructure) { cam.GetComponent<MouseLook>().enabled = false; } else { cam.GetComponent<MouseLook>().enabled = true; } } } void OnGUI() { HealthHunger (); if(chooseStructure) { StructureMenu(); } if(build.warning) { GUI.Label(warningPos, build.warningText); InvokeRepeating("WarningOff", 2, 1); } } void HealthHunger() { GUI.Label (healthpos, "Health:" + health.curHealth + "/" + health.maxHealth); GUI.Label (hungerpos, "Hunger:" + hunger.curHunger + "/" + hunger.maxHunger); GUI.Label (woodpos, "Wood:" + item.woodCount); } void StructureMenu() { if(GUI.Button(cube1pos, "Cube1") && !build.block) { Debug.Log("Cube1 chosen"); build.Cube1 = true; build.Cube2 = false; build.Cube3 = false; build.Cube4 = false; } if(GUI.Button(cube2pos, "Cube2") && !build.block) { Debug.Log("Cube2 chosen"); build.Cube1 = false; build.Cube2 = true; build.Cube3 = false; build.Cube4 = false; } if(GUI.Button(cube3pos, "Cube3") && !build.block) { Debug.Log("Cube3 chosen"); build.Cube1 = false; build.Cube2 = false; build.Cube3 = true; build.Cube4 = false; } if(GUI.Button(cube4pos, "Cube4") && !build.block) { Debug.Log("Cube4 chosen"); build.Cube1 = false; build.Cube2 = false; build.Cube3 = false; build.Cube4 = true; } } void WarningOff() { build.warning = false; CancelInvoke("WarningOff"); } } still error NullReferenceException: Object reference not set to an instance of an object and i have attached main camera ;/
  13. Hmm i can't assign it o.O i drag and drop but .. nothing .. totally ;/ i have this at start: warning CS0436: The type `MouseLook' conflicts with the imported type `MouseLook'. Ignoring the imported type definition i try with this: GameObject.FindWithTag("Player").GetComponent<MouseLook>(); and too nothing ;/
  14. using UnityEngine; using System.Collections; public class UI : MonoBehaviour { public MouseLook mouseLook; void Start() { mouseLook = GetComponent<MouseLook>(); } void Update() { if(Input.GetKeyDown(KeyCode.E)) { chooseStructure = true; mouseLook.enabled = false; //GameObject.Find("Player").GetComponent<MouseLook>().enabled = false; } if(Input.GetKeyDown(KeyCode.Q)) { chooseStructure = false; mouseLook.enabled = true; //GameObject.Find("Player").GetComponent<MouseLook>().enabled = true; } } } I have this and it doesn't work, i mean it show error: NullReferenceException: Object reference not set to an instance of an object and nothing happens i dont know why. I want to disable camera movment when i press E and turn in back on when press Q
  15. Hey guys i have this: using UnityEngine; using System.Collections; public class Build : MonoBehaviour { public GameObject cube; public bool Active; void Start () { } void Update () { if(Input.GetKeyDown(KeyCode. && !Active) { cube = Instantiate(cube, transform.position + transform.forward * 4.0f, transform.rotation) as GameObject; Active = true; cube.transform.parent = Camera.main.transform; cube.rigidbody.isKinematic = true; } if(Input.GetKeyDown(KeyCode.V) && Active) { cube.transform.parent = null; cube.rigidbody.isKinematic = false; Active = false; } } } Now i want to spawn a Cube in front of me and move it around (attached to camera) then when i hit V i want to place it on the ground. This code work, but i when im moveing it around my cube need to collide with ground, trees, etc... and freeze Y (i want to move this cube only by X and Z). What i must change ? BTW sorry for my english (and your eyes propably XD )
×
×
  • Create New...