首页 > 其他分享 >Unity类银河恶魔城学习记录11-1 p103 Item源代码

Unity类银河恶魔城学习记录11-1 p103 Item源代码

时间:2024-03-18 20:30:12浏览次数:17  
标签:11 ItemData System p103 Collections private using 源代码 public

 Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

ItemData.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[CreateAssetMenu(fileName = "New Item Data", menuName = "Data/Item")]
public class ItemData : ScriptableObject 
{
    public string itemName;
    public Sprite icon;//图标
}

ItemObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemObject : MonoBehaviour
{
    private SpriteRenderer sr;

    [SerializeField] private ItemData ItemData;

    private void Start()
    {
        sr = GetComponent<SpriteRenderer>();

        sr.sprite = ItemData.icon;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.GetComponent<Player>()!= null)
        {
            Debug.Log("Picked up item" + ItemData.itemName);
            Destroy(gameObject);
        }
    }

}

 

标签:11,ItemData,System,p103,Collections,private,using,源代码,public
From: https://blog.csdn.net/Homura_/article/details/136820501

相关文章