Unity中通过按键改变物体颜色


 1. using UnityEngine; using System.Collections;

    public class ChangeColor : MonoBehaviour {

        // Use this for initialization  void Start () {         }       // Update
    is called once per frame    void Update () {
            if (Input.GetKeyDown(KeyCode.A))
            {
                this.GetComponent().material.color = Color.red;
            }
            if (Input.GetKeyDown(KeyCode.B))
            {
                this.GetComponent().material.color = Color.yellow;
            }   } }
  1. 将该脚本挂载到目标物上,运行,通过设置按键改变颜色即可
  2. 效果如下图所示
    Unity中通过按键改变物体颜色_第1张图片

你可能感兴趣的:(Unity-物体操作)