首页 > 解决方案 > Assets\Scripts\Player.cs(19,45):错误 CS0117:“颜色”不包含“红色”的定义

问题描述

Assets\Scripts\Player.cs(19,45):错误 CS0117:“颜色”不包含“红色”的定义

using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Color = System.Drawing.Color;


public class Player : MonoBehaviour
{

    public SpriteRenderer[] renderers;

    private void Start() {
        renderers[0].material.color = Color.red;
    }
}

标签: c#unity3d

解决方案


Unity 不使用该System.Drawing.Color结构。你需要UnityEngine.Color改用。您需要做的就是删除这些行using Color = System.Drawing.Color;using System.Drawing;并且您将使用正确的Color结构,该结构确实Color.red. 见下文:

using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Player : MonoBehaviour
{

    public SpriteRenderer[] renderers;

    private void Start() {
        renderers[0].material.color = Color.red;
    }
}

推荐阅读