I can t drag my object from the photo I want to fade in/out into this field, but I m sure I put this script in the canvas. Already tried everything in my opinion, but nothing comes out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Fade : MonoBehaviour
{
[SerializeField] private CanvasGroup canvasgroup;
private bool _fadein = false;
private bool _fadeout = false;
public float TimeToFade;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(_fadein){
if(canvasgroup.alpha < 1){
canvasgroup.alpha += TimeToFade * Time.deltaTime;
if(canvasgroup.alpha >= 1){
_fadein=false;
}
}
}
if(_fadeout){
if(canvasgroup.alpha >= 0){
canvasgroup.alpha -= TimeToFade * Time.deltaTime;
if(canvasgroup.alpha == 0){
_fadeout=false;
}
}
}
}
public void FadeIn()
{
_fadein = true;
}
public void FadeOut()
{
_fadein = false;
}
}
================================================================================================================================================================================================================================================================