用NGUI动态添加和删除Sprite

57 篇文章 2 订阅
34 篇文章 0 订阅
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://5152481.blog.51cto.com/5142481/1601426

using UnityEngine;
using System.Collections;


public class NGUI_button : MonoBehaviour {

   public UIButton button1;    
   public UIButton button2;

    void Start () {
                
    UIButton exe1=button1.GetComponent<UIButton>();//获取组件的方式
    UIButton exe2=button2.GetComponent<UIButton>();
        
    }
    
    void Update () {
    
    }

    void opnedButton1(GameObject obj)
    {
      


      if(obj.name=="Button01")
      {
      UIAtlas atlas=Resources.Load("Textrue/Atlas/Text Atlas",typeof(UIAtlas))as UIAtlas;  //必须建一个Resources 文件夹 ,在他下面放制作好的图集
      GameObject parent=GameObject.Find("point"); //在U3D里面建一个空物体  在这个空物体身上加UIGrid这个脚本 .他时NGUI的脚本。
      UISprite sprite=NGUITools.AddSprite(parent,atlas,"xiaofeiji");//要更换的图片名字
      sprite.MakePixelPerfect();
      parent.GetComponent<UIGrid>().repositionNow=true;
   
      }
      else
      {
        Destroy(GameObject.Find("Sprite"));//删除这个图片

      }

    }

    }


//使用说明  先建一个UIroot  在他下面建2个Button  ,

本文出自 “酷酷小乔” 博客,请务必保留此出处http://5152481.blog.51cto.com/5142481/1601426

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值