mirror of
https://github.com/Steffo99/gravity-fusion.git
synced 2024-11-22 08:24:17 +00:00
Add SlowlyDisappear component
This commit is contained in:
parent
bd75ae9524
commit
005229e2c3
3 changed files with 58 additions and 0 deletions
33
Assets/Components/SlowlyDisappear.cs
Normal file
33
Assets/Components/SlowlyDisappear.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class SlowlyDisappear : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float disappearAfter;
|
||||||
|
protected float timeLeft;
|
||||||
|
protected SpriteRenderer sprite;
|
||||||
|
|
||||||
|
protected float FractionLeft {
|
||||||
|
get {
|
||||||
|
return timeLeft / disappearAfter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start() {
|
||||||
|
sprite = GetComponent<SpriteRenderer>();
|
||||||
|
timeLeft = disappearAfter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update() {
|
||||||
|
timeLeft -= Time.deltaTime;
|
||||||
|
|
||||||
|
if(sprite != null) {
|
||||||
|
sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, FractionLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timeLeft < 0) {
|
||||||
|
Destroy(this.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Components/SlowlyDisappear.cs.meta
Normal file
11
Assets/Components/SlowlyDisappear.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8cb7610d172100841907b194dece1565
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -13,6 +13,7 @@ GameObject:
|
||||||
- component: {fileID: 5473375028011702753}
|
- component: {fileID: 5473375028011702753}
|
||||||
- component: {fileID: 5473375028011702752}
|
- component: {fileID: 5473375028011702752}
|
||||||
- component: {fileID: 5473375028011702755}
|
- component: {fileID: 5473375028011702755}
|
||||||
|
- component: {fileID: 5319285082587561044}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Gravitation Object
|
m_Name: Gravitation Object
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -135,6 +136,19 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
positionInList: 0
|
positionInList: 0
|
||||||
|
--- !u!114 &5319285082587561044
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5473375028011702754}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 8cb7610d172100841907b194dece1565, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
disappearAfter: 5
|
||||||
--- !u!1 &8635663089806839545
|
--- !u!1 &8635663089806839545
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
Loading…
Reference in a new issue