Skip to content

Instantly share code, notes, and snippets.

@kanglicheng
Forked from vjgrayman/Classes1A_Item.cs
Created July 24, 2019 02:14
Show Gist options
  • Save kanglicheng/6ff64550be1df5b2b236f9d03f40fd82 to your computer and use it in GitHub Desktop.
Save kanglicheng/6ff64550be1df5b2b236f9d03f40fd82 to your computer and use it in GitHub Desktop.
[CSharpSurviver_5]#CSharp
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Item
{
[SerializeField]
public string name;
public int id;
public string description;
public Sprite icon;
//This is Item Constructor Method
public Item()
{
}
public Item(string name, int id, string description)
{
this.name = name;
this.id = id;
this.description = description;
}
}
// vim: syntax=CSharp
// Script file should be in "Empty GameObject(named ItemDatabase)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemDatabase : MonoBehaviour
{
public Item[] items;
/*
public Item sword;
public Item hammer;
public Item bread;
*/
// Start is called before the first frame update
void Start()
{
Debug.Log(items[0].name);
/*
sword = new Item();
sword.name = "Sword";
sword.id = 1;
sword.description = "This is a sword!";
// 상위 클라스에 콘스트럭터를 만들어 두면 아래처럼 직접입력 가능
hammer = new Item("Hammer", 2, "This is a Hammer!");
bread = CreateItem("Bread", 3, "I can eat this.");
*/
}
/*
private Item CreateItem(string name, int id, string description)
{
var item = new Item(name, id, description);
return item;
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment