当前位置:网站首页>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;
}
}
}
}
}
边栏推荐
- Applet graduation project based on wechat selection voting applet graduation project opening report function reference
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- High level application of SQL statements in MySQL database (I)
- It's corrected. There's one missing < /script >, why doesn't the following template come out?
- Write the first CUDA program
- Pytoch residual network RESNET
- Problems and solutions of several concurrent scenarios of redis
- Why is the operation unsuccessful (unresolved) uncaught syntaxerror: invalid or unexpected token (resolved)
- Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
- Introduction to graphics: graphic painting (I)
猜你喜欢
Advanced learning of MySQL -- Application -- storage engine
Jerry's modification setting status [chapter]
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
17. File i/o buffer
Pytoch residual network RESNET
Yyds dry goods inventory override and virtual of classes in C
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
FRP intranet penetration
随机推荐
false sharing
Sword finger offer 20 String representing numeric value
The difference between int (1) and int (10)
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Format character%* s
Key knowledge of C language
MySQL workbench use
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
Will the memory of ParticleSystem be affected by maxparticles
Jerry's watch information type table [chapter]
Description of setting items of Jerry [chapter]
Advanced learning of MySQL -- Application -- index
It's corrected. There's one missing < /script >, why doesn't the following template come out?
SQL statement
Leetcode 110 balanced binary tree
Write the first CUDA program
Node write API
Neo4j learning notes
Introduction to graphics: graphic painting (I)
Learn these super practical Google browser skills, girls casually flirt