- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
unityd游戏开发之背包系统()【DOC精选】
背包系统(二)
7、拖入两个物品预设体到格子里面,并为其添加数量
8、修改物品脚本,实现两个物品可以交换
?//重写OnDragDropRelease方法
? ? protected override void OnDragDropRelease(GameObject surface)
? ? {
? ? ? ? base.OnDragDropRelease(surface);//调用父类的OnDragDropRelease(surface)方法
? ? ? ? if (surface.tag == Cell)
? ? ? ? {
? ? ? ? ? ? this.transform.parent = surface.transform; //把背包放入格子里面
? ? ? ? ? ? this.transform.localPosition = Vector3.zero;//把背包居中
? ? ? ? }
? ? ? ? else if (surface.tag == Knapsack)
? ? ? ? {
? ? ? ? ? ? //第一个背包:拖动的背包
? ? ? ? ? ? //第二个背包:将要被交换的背包
? ? ? ? ? ? Transform parent = surface.transform.parent;//得到第二个格子Transform对象
? ? ? ? ? ? surface.transform.parent = this.transform.parent;//把第二个背包放入第一个格子里面
? ? ? ? ? ? surface.transform.localPosition = Vector3.zero;//把第二个背包居中
? ? ? ? ? ? this.transform.parent = parent;//把第一个背包放入第二个格子里面
? ? ? ? ? ? this.transform.localPosition = Vector3.zero;//把第一个背包居中
? ? ? ? }
? ? }
9、修改格子脚本,实现按下F键,随机产生物品【狗刨学习网】
public GameObject[] cells;//9个格子
? ? public string[] knapsacksName;//三个物品的名称
? ? public GameObject item;//任意一个物品
? ? void Update() {?
? ? ? ? if(Input.GetKeyDown(KeyCode.F)){//按下F键
? ? ? ? ? ? PickUp();//调用 PickUp()
? ? ? ? }
? ? }
? ? void PickUp() {
? ? ? ? int index = Random.Range(0, knapsacksName.Length);//随机生成0,1,2三个数其中一个
? ? ? ? string name = knapsacksName[index];//得到随机的物品名称
? ? ? ? for (int i = 0; i cells.Length; i++)
? ? ? ? {
? ? ? ? ? ? if (cells[i].transform.childCount == 0)//当前格子里面没有物品
? ? ? ? ? ? {
? ? ? ? ? ? ? ? GameObject go = NGUITools.AddChild(cells[i], item);//把新生成的物品放入格子里面
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? go.GetComponentUISprite().spriteName = name;//为新生成的物品添加名称
? ? ? ? ? ? ? ? go.transform.localPosition = Vector3.zero;//把物品居中
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
}这篇文章来自狗刨学习网
您可能关注的文档
- Unit Safety First【DOC精选】.doc
- Unit Shapes【DOC精选】.doc
- Unit Saving the world教案【DOC精选】.doc
- UNIT SIGNAL WORDS【DOC精选】.doc
- Unit The birth of blue jeans【DOC精选】.doc
- Unit The land down under【DOC精选】.doc
- Unit The Light of Depression Words and Expressions综合教程一【DOC精选】.doc
- Unit The Richest Man in America【DOC精选】.doc
- Unit The unit of translation【DOC精选】.doc
- Unit Welcome Back To School!【DOC精选】.doc
文档评论(0)