Я хотел обеспечить прозрачность, чтобы это выглядело хорошо, но «не могу изменить возвращаемое значение «material.color», потому что это не переменная».
Я также пытался придать ему новый цвет в RGB, чтобы он мог иметь прозрачность, но все равно не получилось. работает.
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using UnityEngine;
using UnityEngine.ProBuilder.Shapes;
using Color = System.Drawing.Color;
public class Rainbow : MonoBehaviour
{
private float effsped = 15;
private float hue;
private float sat=0.68f;
private float bri = 1;
private MeshRenderer MR;
Color32 objcolor;
// Start is called before the first frame update
void Start()
{
MR = GetComponent();
hue = Random.Range(0f, 1f);
MR.material.color = UnityEngine.Color.HSVToRGB(hue, sat, bri);
}
// Update is called once per frame
void Update()
{
UnityEngine.Color.RGBToHSV(MR.material.color, out hue, out sat, out bri);
hue += (effsped / 10000);
if (hue >= 0.99f)
{
hue = 0f;
}
MR.material.color = UnityEngine.Color.HSVToRGB(hue, sat, bri, true);
Color hastrancy = new Color(MR.material.color.r, MR.material.color.g, MR.material.color.b, 0.8f);
MR.material.SetColor("_Color", hastrancy);
}
}
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using UnityEngine;
using Color = System.Drawing.Color;
public class Rainbowinv : MonoBehaviour
{
private float effsped = 15;
private float hue;
private float sat=0.68f;
private float bri = 1;
private MeshRenderer MR;
// Start is called before the first frame update
void Start()
{
MR = GetComponent();
hue = Random.Range(0f, 1f);
MR.material.color = UnityEngine.Color.HSVToRGB(hue, sat, bri);
}
// Update is called once per frame
void Update()
{
UnityEngine.Color.RGBToHSV(MR.material.color, out hue, out sat, out bri);
hue -= (effsped / 10000);
if (hue
Подробнее здесь: [url]https://stackoverflow.com/questions/78692007/i-cant-give-transparency-to-gameobject-in-unity[/url]