50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 用来塞的钱那个类,但是是小怪打死后掉落的那种
|
||
|
/// </summary>
|
||
|
[RequireComponent(typeof(BoxCollider2D))]
|
||
|
[RequireComponent(typeof(Rigidbody2D))]
|
||
|
public class Coin : MonoBehaviour
|
||
|
{
|
||
|
public Rigidbody2D m_rigidbody;
|
||
|
|
||
|
void Start(){
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
void Init(){
|
||
|
m_rigidbody = GetComponent<Rigidbody2D>();
|
||
|
transform.GetChild(0).gameObject.AddComponent<PickUpCoin>().owner = this;
|
||
|
}
|
||
|
|
||
|
public void PlayerPickUpMe(){
|
||
|
Destroy(gameObject);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 本类的工具类,初始化时给子物体装一个组件,用来检测玩家是否能捡拾硬币
|
||
|
/// </summary>
|
||
|
private class PickUpCoin : Interactive
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 这个捡拾范围所存在于的硬币
|
||
|
/// </summary>
|
||
|
public Coin owner;
|
||
|
void Start(){
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
private void Init(){
|
||
|
itemName = ItemName.硬币;
|
||
|
}
|
||
|
public override void OnCall(){
|
||
|
owner.PlayerPickUpMe();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|