找回密码
 立即注册
查看: 5741|回复: 90

[脚本] 数组定义贴图代码

  [复制链接]
发表于 2012-12-26 19:10 | 显示全部楼层 |阅读模式
本代码按F1键动态改变贴图
[code=csharp]using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{

    //宣告gameobject
    public GameObject ani;                     
   
    //宣告textureObject物件用來放置貼圖物件
    public GameObject textureObject;

    //宣告textures陣列用來放置貼圖
    public Texture[] textures;
  
    //宣告變數y來變化貼圖
    private int y=0;
  

  
   
    void Start()
    {

    }

     //用按鍵換圖片
    void Update()
    {
      
        if (Input.GetKeyDown(KeyCode.F11))         
       {
           y++;
           mm(y);

       }
     
    }

  
    public void mm(int y)
    {
      

        if (y == 1)
        {
           
            textureObject.renderer.materials[0].mainTexture = textures[0];
            
        }
        if (y == 2)
        {
           

            textureObject.renderer.materials[0].mainTexture = textures[1];
            
        }

        if (y == 3)
        {
            
            textureObject.renderer.materials[0].mainTexture = textures[2];
            
        }

    }

  



}[/code]
发表于 2017-5-11 08:34 | 显示全部楼层
很不错
发表于 2017-5-11 08:29 | 显示全部楼层
好帖就是要顶
发表于 2017-5-11 08:25 | 显示全部楼层
顶顶多好
发表于 2017-5-11 08:46 | 显示全部楼层
真心顶
发表于 2017-5-11 08:38 | 显示全部楼层
不错不错
发表于 2017-5-16 11:59 | 显示全部楼层
很不错
发表于 2017-5-16 12:15 | 显示全部楼层
楼主是超人
发表于 2017-5-16 12:10 | 显示全部楼层
顶顶多好
发表于 2017-5-16 12:24 | 显示全部楼层
很好哦
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-28 16:55 , Processed in 0.099923 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表