当前位置:网站首页>Unity knapsack system (code to center and exchange items)
Unity knapsack system (code to center and exchange items)
2022-07-04 02:27:00 【LiPing122335】
Delete UIDrag Drop Item, Add... To the grid Box Collider
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BeiBao : UIDragDropItem {
public UILabel numText;//
int count = 0;
public void AddNum(int num)
{
count += num;
numText.text = count.ToString();
}
protected override void OnDragDropRelease(GameObject p)
{
base.OnDragDropRelease(p);
if (p.CompareTag("GeZi"))
{
transform.parent = p.transform;// Regard the object that the object collides with as the parent
transform.localPosition = Vector3.zero;
}
else if(p.CompareTag ("WuPei"))
{
Transform parent = p.transform.parent;
p.transform.parent = transform.parent;// Exchange parent with encountered object
p.transform.localPosition = Vector3.zero;
transform.parent = parent;
transform.localPosition = Vector3.zero;
}
}
public class MyBeiBao : MonoBehaviour {
public GameObject[] gezi;
public string[] WuPinName;
public GameObject WuPin;
void Update()
{
if (Input .GetKeyDown (KeyCode.P))
{
PrickUp();
}
}
public void PrickUp()
{
int index = Random.Range(0, WuPinName.Length);
string name = WuPinName[index];
for (int i = 0; i < gezi.Length; i++)
{
if (gezi[i].transform.childCount == 0)// No items
{
GameObject go = NGUITools.AddChild(gezi[i], WuPin);// Generate items
go.GetComponent<UISprite>().spriteName = name;
go.transform.localPosition = Vector3.zero;
break;
}
else
{
BeiBao b = gezi[i].transform.GetChild(0).GetComponent<BeiBao>();
if (gezi[i].transform .GetChild (0).GetComponent<UISprite>().spriteName.Equals (name))// Find the item - picture
{
print("qq");
b.AddNum(1);
break;
}
}
}
}
}
边栏推荐
- Small program graduation project based on wechat e-book small program graduation project opening report function reference
- Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization
- Small program graduation project based on wechat reservation small program graduation project opening report reference
- C learning notes: C foundation - Language & characteristics interpretation
- It's corrected. There's one missing < /script >, why doesn't the following template come out?
- Global and Chinese market of contour projectors 2022-2028: Research Report on technology, participants, trends, market size and share
- What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
- 查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題
- 13. Time conversion function
- Latex tips slash \backslash
猜你喜欢
17. File i/o buffer
Basic editing specifications and variables of shell script
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
Learn these super practical Google browser skills, girls casually flirt
FRP intranet penetration
Save Private Ryan - map building + voltage dp+deque+ shortest circuit
Redis transaction
LV1 previous life archives
High level application of SQL statements in MySQL database (I)
Write the first CUDA program
随机推荐
String: LV1 eat hot pot
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Setting function of Jerry's watch management device [chapter]
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
FRP intranet penetration
VRRP+BFD
PMP daily three questions (February 14, 2022)
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
Write the first CUDA program
Question C: Huffman tree
Neo4j learning notes
求esp32C3板子連接mssql方法
A. ABC
LV1 previous life archives
From the 18th line to the first line, the new story of the network security industry
STM32 key content
ZABBIX API batch delete a template of the host
2022 new examination questions for safety management personnel of hazardous chemical business units and certificate examination for safety management personnel of hazardous chemical business units
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends