public override void SetMaterial(string shaderTextureName, Renderer renderer, int…
- User
public override void SetMaterial(string shaderTextureName, Renderer renderer, int transparent) { var videoPlayer = renderer.GetComponent(); if (videoPlayer != null) { Object.Destroy(videoPlayer); }
codevar goSpriteRenderer = renderer.GetComponent<SpriteRenderer>(); if (goSpriteRenderer) { goSpriteRenderer.sprite = this.sprite; } var goSpriteMask = renderer.GetComponent<SpriteMask>(); if (goSpriteMask) { goSpriteMask.sprite = this.sprite; } return; } transparent 是 1-255的值 ,如何设置 goSpriteRenderer.sprite的color的透明度为 transparent - Assistant
In Unity, the SpriteRenderer component has a
colorproperty that can be used to change the color of the sprite, including its transparency or alpha value. Thecolorproperty is aColorstruct which contains four components: red (R), green (G), blue (B), and alpha (A) for transparency. Each of these components is a float value that ranges from 0 to 1.If you have a
transparentvalue that is an integer from 1 to 255 and you want to set the alpha of the sprite renderer to match this transparency level, you will need to convert the integer value into a float value between 0 and 1, because the alpha component of the property expects a float in this range.