Created
March 8, 2019 07:52
-
-
Save gtk2k/3b17fc1ae4b9737feaecc1f2562afee2 to your computer and use it in GitHub Desktop.
RGBAそれぞれの値を個別に変更したい場合(例ではA)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
using UnityEngine; | |
public class ColorTest : MonoBehaviour | |
{ | |
[StructLayout(LayoutKind.Explicit)] | |
public struct Color32RGBA | |
{ | |
[FieldOffset(0)] | |
public byte R; | |
[FieldOffset(1)] | |
public byte G; | |
[FieldOffset(2)] | |
public byte B; | |
[FieldOffset(3)] | |
public byte A; | |
[FieldOffset(0)] | |
public Color32 color; | |
} | |
Material mat; | |
Color32RGBA rgba; | |
void Start() | |
{ | |
rgba = new Color32RGBA(); | |
rgba.color = new Color32(); | |
mat = GetComponent<Renderer>().material; | |
mat.color = rgba.color; | |
} | |
void Update() | |
{ | |
if (rgba.A == 255) | |
rgba.A = 0; | |
else | |
rgba.A++; | |
mat.color = rgba.color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment