I want to change the transparency of the image inserted into Unity Sprite.

Asked 2 years ago, Updated 2 years ago, 145 views

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

public class appear : MonoBehaviour {

    Color color;

    // // Use this for initialization
    void Start () {
        SpriteRenderer spr = GetComponent<SpriteRenderer>();
        color.a = 0;
        spr.color = color;
    }

    // // Update is called once per frame
    void Update () {
        SpriteRenderer spr = GetComponent<SpriteRenderer>();
        color.a += 0.02f;
        spr.color = color;
    }
}

This is how I tried to increase the transparency of the sprite gradually, but when I ran it, it kept transparent. When I checked the inspector window, the value of A in the image is clearly increasing, but it is still transparent on the screen.

unity

2022-09-22 18:53

1 Answers

From Update

spr.color = new Color(spg.color.red, spg.color.green, spg.color.blue, spg.color.red + 0.02f);

I think we can do it


2022-09-22 18:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.