-
-
Save kanglicheng/6ff64550be1df5b2b236f9d03f40fd82 to your computer and use it in GitHub Desktop.
[CSharpSurviver_5]#CSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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