Hello! I’ve been trying for a few hours to get a little “fade” effect after picking up a coin (just before the “Destroy (gameObject)”).
Looking here and there I found something that, at first I thought it would work, but by deactivating the if that controls when it has reached a certain alpha level, I see that it certainly does not work.
Could someone guide me a little?
Thank you very much.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour {
public static int coinsCollected = 0;
public static int coinNeededForWin = 10;
public AudioClip clip; // coin collected sound
public ParticleSystem particle; // particle when we take the coin
private bool coinAlreadyCollected = false; // just for not take the coin two times, just in case.
private Color alphaColour; // alpha for the coin
private Color alphaColourParticle; // alpha for the particle
void Awake()
{
alphaColour.a = gameObject.GetComponent<Renderer> ().material.color.a;
alphaColourParticle.a = particle.GetComponent<Renderer> ().material.color.a;
}
void Update()
{
this.transform.Rotate(1f, 1f, 2f);
if (coinAlreadyCollected == true) //Let's say goodbye to the coin collected.
{
alphaColour.a -= 0.05f;
alphaColourParticle.a -= 0.05f;
if (alphaColour.a <= -2.0f){Destroy (gameObject,0.1f);}
}
}
// More things unrelated
}