当前位置:网站首页>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;
}
}
}
}
}
边栏推荐
- Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
- Johnson–Lindenstrauss Lemma
- C learning notes: C foundation - Language & characteristics interpretation
- Description of setting items of Jerry [chapter]
- Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
- Mysql to PostgreSQL real-time data synchronization practice sharing
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
- [Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
- What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
猜你喜欢
![[software implementation series] software implementation interview questions with SQL joint query diagram](/img/8b/8718fea82f83a6169ea5d8c2e5b645.jpg)
[software implementation series] software implementation interview questions with SQL joint query diagram

Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files

Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales

LV1 previous life archives

Talking about custom conditions and handling errors in MySQL Foundation
![[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)](/img/36/e5b716f2f976eb474b673f85363dae.jpg)
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)

High level application of SQL statements in MySQL database (I)

IPv6 experiment

Pytoch residual network RESNET

AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
随机推荐
STM32 key content
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Remember another interview trip to Ali, which ends on three sides
Crawler practice website image batch download
Key knowledge of C language
Write the first CUDA program
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
Life cycle of instance variables, static variables and local variables
Will the memory of ParticleSystem be affected by maxparticles
Small program graduation project based on wechat e-book small program graduation project opening report function reference
Latex tips slash \backslash
The difference between int (1) and int (10)
1189. Maximum number of "balloons"
Pagoda SSL can't be accessed? 443 port occupied? resolvent
Bacteriostatic circle scanning correction template
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
Take you to master the formatter of visual studio code
Gee import SHP data - crop image
Setting function of Jerry's watch management device [chapter]