当前位置:网站首页>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;
}
}
}
}
}
边栏推荐
- What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
- Network byte order
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- Question C: Huffman tree
- Winter vacation daily question -- a single element in an ordered array
- Applet graduation project based on wechat selection voting applet graduation project opening report function reference
- What is the intelligent monitoring system of sewage lifting pump station and does it play a big role
- Neo4j learning notes
- Advanced learning of MySQL -- Application -- storage engine
- The difference between lambda expressions and anonymous inner classes
猜你喜欢
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
MySQL workbench use
Bugku Zhi, you have to stop him
Write the first CUDA program
Will the memory of ParticleSystem be affected by maxparticles
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
String & memory function (detailed explanation)
Setting function of Jerry's watch management device [chapter]
Gee import SHP data - crop image
Learn these super practical Google browser skills, girls casually flirt
随机推荐
中電資訊-信貸業務數字化轉型如何從星空到指尖?
SQL statement
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
C language black Technology: Archimedes spiral! Novel, interesting, advanced~
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
Node write API
Keep an IT training diary 055- moral bitch
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
Optimization theory: definition of convex function + generalized convex function
Properties of binary trees (numerical aspects)
FRP intranet penetration
Pagoda SSL can't be accessed? 443 port occupied? resolvent
From the 18th line to the first line, the new story of the network security industry
A fan summed up so many interview questions for you. There is always one you need!
Sword finger offer 20 String representing numeric value
The difference between lambda expressions and anonymous inner classes
ZABBIX API pulls the values of all hosts of a monitoring item and saves them in Excel
Key knowledge of C language
Kiss number + close contact problem