_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/SnailHouse/SnailPanel.cs

68 lines
1.9 KiB
C#
Raw Normal View History

2024-12-08 20:16:04 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SnailPanel : MonoBehaviour
{
public static SnailPanel Instance { get; private set; }
public GameObject snailPrefab; // <20><>ţ<EFBFBD><C5A3>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public float width ; // <20>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
public float height ; // <20>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ߶<C4B8>
public Vector2 startPosition = new Vector2(0f, 0f); // <20><>ʼλ<CABC><CEBB>
private UserSnail usersnail;
public List<GameObject> Snails;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
// Start is called before the first frame update
async void Start()
{
queryUserSnailCount queryUserSnailCount = new queryUserSnailCount();
//9.2<EFBFBD><EFBFBD>ѯ<EFBFBD>ҵĹ<EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>󶨵<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
usersnail = await queryUserSnailCount.QueryUserSnailCount();
SpawnSnails();
Debug.Log(usersnail.data.Count);
}
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7>
void SpawnSnails( )
{
for (int i = 0; i < usersnail.data.Count&&i<=10; i++)
{
float x = startPosition.x + (Random.Range(-(width / 2), (width / 2))) ;
float y = startPosition.y + (Random.Range(-(height / 2), (height / 2)));
Vector3 spawnPosition = new Vector3(x, y, 0f); //
GameObject ob =Instantiate(snailPrefab);
ob.transform.SetParent(transform);
ob.transform.localPosition = spawnPosition;
Snailmove snailmove = ob.GetComponent<Snailmove>();
2024-12-09 12:00:50 +08:00
snailmove.id = usersnail.data[i].id;
Debug.Log(usersnail.data[i].id);
2024-12-08 20:16:04 +08:00
Snails.Add(ob);
}
}
}