Search Unity

[KINDA SOLVED] Fade In Spawned Object

Discussion in 'Scripting' started by zThana, Mar 5, 2015.

  1. zThana

    zThana

    Joined:
    Dec 5, 2014
    Posts:
    18
    Heey,

    I got this piece of code; http://hastebin.com/iyikededin.coffee
    But I want the spawned "Bullet" to fade in when it spawns.
    Fading out will be optionally ;3

    So... How?

    - Pr0totype2
     
  2. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
  3. zThana

    zThana

    Joined:
    Dec 5, 2014
    Posts:
    18
    Thanks, but wouldn't it be better if I make the visibility of the bullet 0 at start, and in 0,2 seconds, visibility will be 100?
    And it goes through the 0 to 100 in 0,2 seconds?
     
  4. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Last edited: Mar 6, 2015
  5. zThana

    zThana

    Joined:
    Dec 5, 2014
    Posts:
    18
    Alright, thanks!
     
  6. mmcveigh33

    mmcveigh33

    Joined:
    May 23, 2019
    Posts:
    3
    Not sure if this is horrible way to go about this, but I achieved this by adding an LOD group to my object, and then from script, setting LODGroup.localReferencePoint to something really far away like new Vector3(99999999,0,9999999) and then invoking a fade in method after a delay where I reset the localReferencePoint to its original. Then just change the fade mode on the LOD group component to cross fade and check Animate cross-fading

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [RequireComponent(typeof(LODGroup))]
    6. public class LODFade : MonoBehaviour
    7. {
    8.   // Start is called before the first frame update
    9.   Vector3 ogRefPoint;
    10.   LODGroup lodGroup;
    11.   void Awake()
    12.   {
    13.       lodGroup = GetComponent<LODGroup>();
    14.       ogRefPoint = lodGroup.localReferencePoint;
    15.       lodGroup.localReferencePoint = new Vector3(99999,0,99999);
    16.       Invoke("FadeIn", 0.2f);
    17.   }
    18.  
    19.   void FadeIn() {
    20.     lodGroup.localReferencePoint = ogRefPoint;
    21.   }
    22. }