Hello,
I am running into some issues using CanvasGroup and setting alpha.
My desired behavior is to display a canvasGroup with a few nested items when an object enters a trigger collider.
The OnPackageDelivery function is called externally and sets the canvasGroup alpha to 1.
This works fine if I trigger it with a mouse click (in my update function), but does not work at all when the function is called after the object enters the trigger.
I know that the trigger is not the problem because print(“show success text”) logs to the console, but the canvasGroup alpha stays at 0.
Any help on this would be appreciated, I feel like I am overlooking something but I cant think of what.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GUI : MonoBehaviour
{
[SerializeField] CanvasGroup successText;
void Start()
{
successText.alpha = 0.0f;
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
OnPackageDelivery();
}
}
public void OnPackageDelivery()
{
// successText.enabled = true;
// successText.gameObject.SetActive(true);
successText.alpha = 1.0f;
print("show success text");
}
}