当前位置:网站首页>Ngui, backpack drag and drop, and random cloning of picture knowledge points
Ngui, backpack drag and drop, and random cloning of picture knowledge points
2022-06-11 10:27:00 【ying1228475251】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* File description :
* founder :
* Creation time :
* Modification time :
* edition :1.0
*/
public class Knapsackltem : UIDragDropItem{
int count = 1;
public UILabel numTxt;// The text above the default body
public void Add()// How to add the quantity of items
{
count++;// Always add up
numTxt.text = count.ToString();// Assign to text
}
protected override void OnDragDropRelease(GameObject surface)//OnDragDropRelease: Drag and drop , discarded , Release
{
base.OnDragDropRelease(surface);// Calls a method of the parent class
print(surface);// Colliding objects
if (surface.CompareTag("GeZi"))
{
// Item Center
transform.parent = surface.transform;// Put your boots in the grid
transform.localPosition = Vector3.zero;// Put your boots right in the middle of the grid
}
else if (surface.CompareTag("WuPin"))
{
// Goods exchange
Transform parent = surface.transform.parent;// The parent of the wrist guard
surface.transform.parent = transform.parent;// Put the wrist guard under your boots
surface.transform.localPosition = Vector3.zero;// The wrist guard is centered
transform.parent = parent;// Put the boots under the wrist guard
transform.localPosition = Vector3.zero;// Boots centered
}
else
{
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* File description :
* founder :
* Creation time :
* Modification time :
* edition :1.0
*/
public class MyKnapsack : MonoBehaviour {
public GameObject[] cells;// lattice
public string[] names;// Item name
public GameObject item;// Current items
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
{
PickUp();
}
}
void PickUp()
{
int index = Random.Range(0, names.Length);// Location
string name = names[index];// Random item picture name
for (int i = 0; i < cells.Length; i++)// Random lattice
{
if (cells[i].transform.childCount == 0)// There are no items in the grid
{
GameObject go = NGUITools.AddChild(cells[i], item);// Clone an item and put it in the grid
go.transform.GetComponent<UISprite>().spriteName = name;// Change item name
go.transform.localPosition = Vector3.zero;// Item Center
break;
}
else// There are items in the grid
{
// Find the picture above the preset
UISprite sprite = cells[i].transform.GetChild(0).GetComponent<UISprite>();
if (sprite.spriteName.Equals(name))
{
sprite.GetComponent<Knapsackltem>().Add();// Call the script above the preset body
break;
}
}
}
}
}
边栏推荐
- Circuit board made of real gold -- golden finger
- C语言课程设计
- What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?
- 接口调优的大致思路
- Knowledge drop - personality analysis - four types of method
- 利用PHP开发的一款万能、表白墙系统部分代码片段
- Batch add noise to data and generate new named annotation files
- 微信小程序之点餐系统附源码
- NGUI,飘血
- puppeteer入门之 BrowserFetcher 类
猜你喜欢

Dynamically render data and carousels

Reprint: linearlayout+fragment to achieve the lower navigation bar effect

Cas de rectification du CEM rayonné par des équipements électroniques

金仓数据库KingbaseES中的sys_checksums坏块检测功能

Differences between beanfactorypostprocessor and beanpostprocessor

BCGControlBar库专业版,完整记录的MFC扩展类

Bcgcontrolbar Library Professional Edition, fully documented MFC extension class

LoRa模块无线收发通信技术详解

Secret behind the chart | explanation of technical indicators: tangqi'an channel

Empire CMS imitates DIY handmade website source code of craft activity /92kaifa imitates self-adaptive mobile phone version template of craft activity
随机推荐
How much do you know about the functions and functions of Rexroth solenoid directional valve
iPhone 15 被迫用上 Type-C 接口
Function and function of wandfluh proportional valve
Circuit board made of real gold -- golden finger
电子设备辐射EMC整改案例
接口调优的大致思路
Dynamically render data and carousels
Pyramidtnt: TNT with characteristic pyramid structure
WordPress网站备份
Preview component packaging graphic tutorial in cadence OrCAD capture schematic design interface
Ugui mouse click diffusion UI effect
微信小程序之点餐系统附源码
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
MySQL transaction
Picture rule page turning
MySQL permission management and backup
BCGControlBar库专业版,完整记录的MFC扩展类
使用bat向文件的第一行中写入内容
puppeteer入门之 Puppeteer 类
Empire CMS imitates DIY handmade website source code of craft activity /92kaifa imitates self-adaptive mobile phone version template of craft activity