美文网首页
Unity物体变色

Unity物体变色

作者: Moment__格调 | 来源:发表于2020-03-13 15:33 被阅读0次
using System.Collections.Generic;
using UnityEngine;

public class CS : MonoBehaviour
{
    private GameObject obj1;
    private Material m1;
    // Start is called before the first frame update
    void Start()
    {

         obj1 = GameObject.Find("Cube");
        Debug.Log(obj1.GetComponent<Renderer>().material.name);
      //  obj1.GetComponent<Renderer>().material.color = Color.white;

    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void SetBtn1()
    {
        // Debug.Log(obj1.GetComponent<Renderer>().material.color.a);
        obj1.GetComponent<Renderer>().material.color = Color.red;
    }
    public void SetBtn2()
    {
        obj1.GetComponent<Renderer>().material.color = Color.yellow;
       // obj1.GetComponent<Material>().color = Color.yellow;
    }
    public void SetBtn3()
    {
        obj1.GetComponent<Renderer>().material.color = Color.blue;
        Invoke("Set1",0.6f);
        
    }
    public void Set1()
    {
        obj1.GetComponent<Renderer>().material.color = Color.Lerp(Color.red,Color.magenta,5f);
    }
//    public void OnDisable()
//    {
//        obj1.GetComponent<Renderer>().material.color = Color.white;
//    }

}

相关文章

  • Unity物体变色

  • Unity物体移动

    FixedUpdate和Update的区别 FixedUpdate是固定秒数更新,Update是每帧更新一次。De...

  • Unity 物体旋转

    transform.rotation方式旋转[#2-%E5%BC%80%E5%8F%91%E7%8E%AF%E5%...

  • Unity动画 旋转约束 RotationConstraint

    简介: 旋转约束也是 Unity 内常用的,约束组件之一,他可以让一个物体模仿另一个物体的旋转。版本:Unity2...

  • 无标题文章

    刚刚发现了一个UNITY3D中物体移动比较齐全的方法,借鉴的,希望对大家都有所帮 unity3d中控制物体移动方法...

  • 界面视图

    首先我们要知道Unity里面的内容构成:场景-物体-组件-脚本(代码)。一个场景是由多个物体构成,而物体又是由多个...

  • Unity渲染顺序总结

    Unity渲染顺序一句话总结Unity物体渲染先后顺序【ShaderLab学习】RenderQueue理解论Ren...

  • Unity 控制物体移动

    按坐标轴移动 public float moveSpeed = 1f;//初始化移动速度为1 transform....

  • Unity物体打组

  • Unity3D中Material与ShareMaterial引用

    我们在使用Unity引擎的时候,有时候需要去修改某个物体上的Material,在Unity的Renderer类里,...

网友评论

      本文标题:Unity物体变色

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