当前位置:网站首页>NGUI,背包拖拽,以及随机克隆图片知识点
NGUI,背包拖拽,以及随机克隆图片知识点
2022-06-11 10:20:00 【ying1228475251】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Knapsackltem : UIDragDropItem{
int count = 1;
public UILabel numTxt;//预设体上面的文本
public void Add()//添加物品的数量方法
{
count++;//一直累加
numTxt.text = count.ToString();//赋值给文本
}
protected override void OnDragDropRelease(GameObject surface)//OnDragDropRelease:拖放,丢弃,释放
{
base.OnDragDropRelease(surface);//调用父类的方法
print(surface);//碰撞的物体
if (surface.CompareTag("GeZi"))
{
//物品居中
transform.parent = surface.transform;//把靴子放到格子里面
transform.localPosition = Vector3.zero;//把靴子放在格子的正中间
}
else if (surface.CompareTag("WuPin"))
{
//物品交换
Transform parent = surface.transform.parent;//护腕的父对象
surface.transform.parent = transform.parent;//把护腕放入靴子下面
surface.transform.localPosition = Vector3.zero;//护腕居中
transform.parent = parent;//把靴子放入护腕下面
transform.localPosition = Vector3.zero;//靴子居中
}
else
{
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class MyKnapsack : MonoBehaviour {
public GameObject[] cells;//格子
public string[] names;//物品名称
public GameObject item;//当前物品
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
{
PickUp();
}
}
void PickUp()
{
int index = Random.Range(0, names.Length);//位置
string name = names[index];//随机物品图片名称
for (int i = 0; i < cells.Length; i++)//随机格子
{
if (cells[i].transform.childCount == 0)//格子里面没有物品
{
GameObject go = NGUITools.AddChild(cells[i], item);//克隆一个物品放到格子里面
go.transform.GetComponent<UISprite>().spriteName = name;//更换物品名称
go.transform.localPosition = Vector3.zero;//物品居中
break;
}
else//格子里面有物品
{
//找到预设体上面的图片
UISprite sprite = cells[i].transform.GetChild(0).GetComponent<UISprite>();
if (sprite.spriteName.Equals(name))
{
sprite.GetComponent<Knapsackltem>().Add();//调用预设体上面的脚本
break;
}
}
}
}
}
边栏推荐
- EMG线性光源发射器有哪些功能和特点呢?
- 锐意进取,砥砺前行,JASMINER持续深耕品牌实力
- parker派克先导式电磁阀和直动式电磁阀的区别有哪些?
- What is digital twin? A real-time and virtual representation
- Can station B make money?
- Pagoda panel backup and recovery data
- After four years of outsourcing, it was abandoned
- Some code fragments of a universal and confession wall system developed by PHP
- BCGControlBar库专业版,完整记录的MFC扩展类
- 面试复习手写题--函数截流与抖动
猜你喜欢

不卷了!入职字节跳动一周就果断跑了。

Q1's revenue exceeded Wall Street's expectations, and the value of Zhiwen group is waiting to return

远程监控项目离线日志说明书

解读USB3.0测试项目

ugui图片墙

TikTok在英国遭遇文化冲突,短期内众多员工离职

锐意进取,砥砺前行,JASMINER持续深耕品牌实力

Correct opening method of RPC | understand go native net/rpc package

MySQL基础篇常用约束总结上篇

ZigBee模块通信协议的树形拓扑组网结构
随机推荐
电子设备辐射EMC整改案例
What hydraulic oil is used for Denison hydraulic pump? What are the requirements
微信小程序之点餐系统附源码
1. system in Library
[torch]: parallel training and can dynamically set the batch size of the first GPU
Picture rule page turning
安装MySQL ,出现由于找不到 MSVCR120.dll,无法继续执行代码解决方法”
[audio and video] Introduction to SEI
手写代码call,apply,bind
利用PHP开发的一款万能、表白墙系统部分代码片段
With determination to forge ahead, JASMINER continues to deepen its brand strength
面试复习手写题--函数截流与抖动
Using exec in PHP to display errors
Mysql--索引
穆格测试控制器的作用和应用场合有哪些
BCGControlBar库专业版,完整记录的MFC扩展类
详述用网络分析仪测量DC-DC和PDN
解读USB3.0测试项目
Excellent test engineer must have 4 safety test methods!
【机器学习理论】True Positive, True Negative, False Positive, False Negative概念