当前位置:网站首页>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;
}
}
}
}
}
边栏推荐
- Pytoch residual network RESNET
- MySQL advanced SQL statement (1)
- 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
- Buuctf QR code
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- false sharing
- Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
- Sword finger offer 20 String representing numeric value
- 12. Gettimeofday() and time()
- Key knowledge of embedded driver
猜你喜欢

Override and virtual of classes in C #

Small program graduation project based on wechat examination small program graduation project opening report function reference

Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!

Introduction to graphics: graphic painting (I)

長文綜述:大腦中的熵、自由能、對稱性和動力學
![Jerry's modification setting status [chapter]](/img/23/d6eb521943b35e543a9681a98ad3be.jpg)
Jerry's modification setting status [chapter]

FRP intranet penetration
![Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine](/img/3a/cf6285ae1c01bda42874eeca9fe5b1.jpg)
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine

Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends

MySQL workbench use
随机推荐
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
17. File i/o buffer
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
From the 18th line to the first line, the new story of the network security industry
Keep an IT training diary 054- opening and closing
ZABBIX API batch delete a template of the host
Create template profile
Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé
MySQL advanced SQL statement (1)
What are the conditions for the opening of Tiktok live broadcast preview?
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)
Why is the operation unsuccessful (unresolved) uncaught syntaxerror: invalid or unexpected token (resolved)
[leetcode daily question] a single element in an ordered array
[Yugong series] February 2022 attack and defense world advanced question misc-84 (MySQL)
13. Time conversion function
Chain ide -- the infrastructure of the metauniverse
Database concept and installation
VRRP+BFD
查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題