美文网首页
每点击一次触发更改一次材质

每点击一次触发更改一次材质

作者: Moment__格调 | 来源:发表于2016-08-26 11:09 被阅读25次

    using UnityEngine;
    using System.Collections;

    public class CubeScript : MonoBehaviour {
    public Material Material01;
    public Material Material02;
    public Material Material03;
    public Material Material04;
    private Material currentMaterial ;
    int i = 0;
    private Renderer rend;
    // Use this for initialization
    void Start () {

        Debug.Log(111);
       // currentMaterial = Material01;
        rend = GetComponent<Renderer>();
        rend.material = Material01;
    }
    
    // Update is called once per frame
    void Update () {
        
        if (Input.GetKeyDown(KeyCode.Joystick1Button0))
        {
            i ++ ;
            Debug.Log(333);
            if (i == 1)
            {
                
                rend.material = Material02;
               // i ++;
                Debug.Log(444);
               // currentMaterial = Material02;
            }
    
            if (i == 2)
            {
    
                Debug.Log(444);
                rend.material = Material03;
                //currentMaterial = Material03;
            }
            if (i == 3)
            {
                rend.material = Material04;
                i = 0;
            }
        }
        
    }
    

    }

    相关文章

      网友评论

          本文标题:每点击一次触发更改一次材质

          本文链接:https://www.haomeiwen.com/subject/rcxzsttx.html