1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-22 17:34:18 +00:00
keep-everything-alive/Assets/Scripts/Generic/RecolorOnCollisionWithEnemy.cs

30 lines
658 B
C#
Raw Normal View History

2020-04-19 14:24:38 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
2020-04-20 01:03:33 +00:00
public class RecolorOnCollisionWithEnemy : MonoBehaviour
2020-04-19 14:24:38 +00:00
{
public Color color;
2020-04-19 15:55:44 +00:00
public float activationDelay = 0.5f;
2020-04-19 14:24:38 +00:00
private SpriteRenderer spriteRenderer;
2020-04-19 15:55:44 +00:00
private bool active;
2020-04-19 14:24:38 +00:00
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
2020-04-19 15:55:44 +00:00
Invoke("Activate", activationDelay);
}
void Activate() {
active = true;
2020-04-19 14:24:38 +00:00
}
2020-04-19 15:55:44 +00:00
void OnTriggerStay2D(Collider2D other) {
if(other.tag == "Enemy" && active) {
2020-04-19 14:24:38 +00:00
spriteRenderer.color = color;
}
}
}