Инвентарь - Форум Игроделов
Чт, 02 Май 2024, 02:10 
 
Приветствую Вас Гость Главная | Регистрация | Вход
Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум Игроделов » UNITY3D » СКРИПТИНГ » Инвентарь
Инвентарь
DartRevanДата: Ср, 16 Дек 2015, 23:26 | Сообщение # 1
Нет аватара
 
Сообщений: 1
Награды: 0
Репутация: 0
Статус: Offline
Здравствуйте, такая проблема, добавил в свой инвентарь Аптечки "Health" и патроны "Ammo"... С аптекой все норм, а вот патроны по факту заряжаются, только если выбросить оружие и поднять снова.
Цитата
public class Inventory : MonoBehaviour
{
List<Item> list;
public GameObject inventory;
public GameObject container;
public MonoBehaviour fps;
public FPSHandR controller2;
public FPSHandL controller;
public Text txt;
public Weapon wp;
int random_ammo;
public Heath hp;

// Use this for initialization
void Start () {
list = new List<Item>();
Cursor.visible=false;
controller2 = GetComponent<FPSHandR> ();
controller = GetComponent<FPSHandL> ();
random_ammo = Random.Range (5, 10);
hp = GetComponent<Heath> ();
wp = GetComponent <Weapon> ();
}
// Update is called once per frame
void Update () {
txt.text = "";
RaycastHit hit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 2.5f)){
if (hit.collider.tag == "Loot"){
txt.text = "Взять:E";
if(Input.GetKeyUp(KeyCode.E))
{
Item item = hit.collider.GetComponent<Item>();
if(item != null)
{
list.Add(item);
Destroy(hit.collider.gameObject);
txt.text = "";
}
}
}
}
if(Input.GetKeyUp(KeyCode.B))
{
if(inventory.activeSelf)
{
fps.enabled = true;
inventory.SetActive(false);
Cursor.visible=false;
for(int i = 0; i < inventory.transform.childCount; i++)
{
if(inventory.transform.GetChild(i).transform.childCount > 0)
{
Destroy(inventory.transform.GetChild(i).transform.GetChild(0).gameObject);
}
}
}
else
{
fps.enabled = false;
inventory.SetActive(true);
Cursor.visible=true;
int count = list.Count;
for(int i = 0; i < count; i++)
{
Item it = list[i];

if(inventory.transform.childCount > i)
{

GameObject img = Instantiate<GameObject>(container);
img.transform.SetParent(inventory.transform.GetChild(i).transform);
img.GetComponent<Image>().sprite = Resources.Load<Sprite>(it.sprite);
img.GetComponent<Drag>().item = it;
}
else break;
}
}
}
}
void use(Drag drag)
{
if (drag.item.type == "LeftHand") {
HandItem myitem = Instantiate<GameObject> (Resources.Load<GameObject> (drag.item.prefab)).GetComponent<HandItem> ();
controller.addHand (myitem);
}
if (drag.item.type == "Ammo") {
wp.ammo += random_ammo;
}
if (drag.item.type == "Health") {
hp.LP += random_ammo;

} else if (drag.item.type == "RightHand") {
HandItem myitem = Instantiate<GameObject> (Resources.Load<GameObject> (drag.item.prefab)).GetComponent<HandItem> ();
controller2.addHand (myitem);
}
list.Remove (drag.item);
Destroy(drag.gameObject);
}

void remove(Drag drag)
{
Item it = drag.item;
GameObject newo = Instantiate<GameObject>(Resources.Load<GameObject>(it.prefab));
newo.transform.position = transform.position + transform.forward + transform.up;
Destroy(drag.gameObject);
list.Remove(it);
}
}


Сообщение отредактировал DartRevan - Ср, 16 Дек 2015, 23:26
 
СообщениеЗдравствуйте, такая проблема, добавил в свой инвентарь Аптечки "Health" и патроны "Ammo"... С аптекой все норм, а вот патроны по факту заряжаются, только если выбросить оружие и поднять снова.
Цитата
public class Inventory : MonoBehaviour
{
List<Item> list;
public GameObject inventory;
public GameObject container;
public MonoBehaviour fps;
public FPSHandR controller2;
public FPSHandL controller;
public Text txt;
public Weapon wp;
int random_ammo;
public Heath hp;

// Use this for initialization
void Start () {
list = new List<Item>();
Cursor.visible=false;
controller2 = GetComponent<FPSHandR> ();
controller = GetComponent<FPSHandL> ();
random_ammo = Random.Range (5, 10);
hp = GetComponent<Heath> ();
wp = GetComponent <Weapon> ();
}
// Update is called once per frame
void Update () {
txt.text = "";
RaycastHit hit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 2.5f)){
if (hit.collider.tag == "Loot"){
txt.text = "Взять:E";
if(Input.GetKeyUp(KeyCode.E))
{
Item item = hit.collider.GetComponent<Item>();
if(item != null)
{
list.Add(item);
Destroy(hit.collider.gameObject);
txt.text = "";
}
}
}
}
if(Input.GetKeyUp(KeyCode.B))
{
if(inventory.activeSelf)
{
fps.enabled = true;
inventory.SetActive(false);
Cursor.visible=false;
for(int i = 0; i < inventory.transform.childCount; i++)
{
if(inventory.transform.GetChild(i).transform.childCount > 0)
{
Destroy(inventory.transform.GetChild(i).transform.GetChild(0).gameObject);
}
}
}
else
{
fps.enabled = false;
inventory.SetActive(true);
Cursor.visible=true;
int count = list.Count;
for(int i = 0; i < count; i++)
{
Item it = list[i];

if(inventory.transform.childCount > i)
{

GameObject img = Instantiate<GameObject>(container);
img.transform.SetParent(inventory.transform.GetChild(i).transform);
img.GetComponent<Image>().sprite = Resources.Load<Sprite>(it.sprite);
img.GetComponent<Drag>().item = it;
}
else break;
}
}
}
}
void use(Drag drag)
{
if (drag.item.type == "LeftHand") {
HandItem myitem = Instantiate<GameObject> (Resources.Load<GameObject> (drag.item.prefab)).GetComponent<HandItem> ();
controller.addHand (myitem);
}
if (drag.item.type == "Ammo") {
wp.ammo += random_ammo;
}
if (drag.item.type == "Health") {
hp.LP += random_ammo;

} else if (drag.item.type == "RightHand") {
HandItem myitem = Instantiate<GameObject> (Resources.Load<GameObject> (drag.item.prefab)).GetComponent<HandItem> ();
controller2.addHand (myitem);
}
list.Remove (drag.item);
Destroy(drag.gameObject);
}

void remove(Drag drag)
{
Item it = drag.item;
GameObject newo = Instantiate<GameObject>(Resources.Load<GameObject>(it.prefab));
newo.transform.position = transform.position + transform.forward + transform.up;
Destroy(drag.gameObject);
list.Remove(it);
}
}

Автор - DartRevan
Дата добавления - 16 Дек 2015 в 23:26
Thedrhax14Дата: Вт, 29 Дек 2015, 10:02 | Сообщение # 2
 
Сообщений: 54
Награды: 0
Репутация: 1
Статус: Offline
В чем проблема?

Виду блог про разроботку игр и про свои проекты https://thedrhax14.wordpress.com/
 
СообщениеВ чем проблема?

Автор - Thedrhax14
Дата добавления - 29 Дек 2015 в 10:02
ЛевшаДата: Вт, 29 Дек 2015, 16:56 | Сообщение # 3
Черный Волк
 
Сообщений: 7257
Награды: 30
Репутация: 3313
Статус: Offline
Цитата Thedrhax14 ()
В чем проблема?

Цитата DartRevan ()
патроны по факту заряжаются, только если выбросить оружие и поднять снова.


X.cor.R (Prologue)
 
Сообщение
Цитата Thedrhax14 ()
В чем проблема?

Цитата DartRevan ()
патроны по факту заряжаются, только если выбросить оружие и поднять снова.

Автор - Левша
Дата добавления - 29 Дек 2015 в 16:56
Форум Игроделов » UNITY3D » СКРИПТИНГ » Инвентарь
  • Страница 1 из 1
  • 1
Поиск:
Загрузка...

Game Creating CommUnity © 2009 - 2024