_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/snailFactory/NoSnailCard.cs
2024-12-09 12:00:50 +08:00

63 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoSnailCard : MonoBehaviour
{
public FactoryItem FactoryItem;
// Start is called before the first frame update
void Start()
{
}
public async void SnailBindCard(long snailid)
{
//9.4
bindSlot bindSlot = new bindSlot();
BindSlot Bs=await bindSlot.QueryUserSnailCount(snailid, FactoryItem.id);
if (Bs.code == 200)
{
SnaolHouse.Instance.InitItem();
// 使用 for 循环来安全地删除元素
for (int i = 0; i < SnailPanel.Instance.Snails.Count; i++)
{
var instanceSnail = SnailPanel.Instance.Snails[i];
if (snailid == instanceSnail.GetComponent<Snailmove>().id)
{
SnailPanel.Instance.Snails.RemoveAt(i); // 删除元素
Destroy(instanceSnail); // 销毁物体
i--; // 删除元素后需要调整索引
}
}
}
else
{
foreach (var instanceSnail in SnailPanel.Instance.Snails)
{
if (snailid == instanceSnail.GetComponent<Snailmove>().id)
{
instanceSnail.gameObject.transform.localPosition = new Vector3(0, 0, 0); // 重置位置
}
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.name == "Snail(Clone)")
{
Snailmove sm = other.gameObject.GetComponent<Snailmove>();
SnailBindCard(sm.id);
}
}
// Update is called once per frame
void Update()
{
this.transform.localScale = new Vector3(1, 1, 1);
}
}