更改颜色后预制件未统一渲染

问题描述 投票:0回答:1

我正在尝试制作一个图块系统,并且我有一个功能可以更改所有其他图块的颜色以制作棋盘图案。但是,当颜色从白色(默认)更改为任何其他颜色后,它就不会显示了。

enter image description here

网格管理器脚本:

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

public class GridManager : MonoBehaviour
{
    [SerializeField] private int width , height;

    [SerializeField] private Tile tilePrefab;

    void Start()
    {
        GenerateGrid();
    }

    void GenerateGrid()
    {
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                var spawnedTile = Instantiate(tilePrefab , new Vector3(x , y) , Quaternion.identity);
                spawnedTile.name = $"Tile {x} {y}";

                var isOffset = (x % 2 == 0 && y % 2 != 0) || (x % 2 != 0 && y % 2 == 0);
                spawnedTile.Init(isOffset);
            }
        }
    }
}

平铺脚本:

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

public class Tile : MonoBehaviour
{
    [SerializeField] private Color baseColor , offsetColor;
    [SerializeField] private SpriteRenderer renderer;

    public void Init(bool isOffset)
    {
        if (isOffset)
        {
            renderer.color = offsetColor;
        }
        else
        {
            renderer.color = baseColor;
        }
    }
}

我尝试在编辑器中手动更改颜色而不调用“Init”函数,效果很好。

unity-game-engine 2d render
1个回答
0
投票

enter image description here

我觉得alpha还是0,改成255..

© www.soinside.com 2019 - 2024. All rights reserved.