init
This commit is contained in:
commit
8103d0d89d
514 changed files with 211049 additions and 0 deletions
65
Assets/Scripts/ButtonEnableDisable.cs
Normal file
65
Assets/Scripts/ButtonEnableDisable.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ButtonEnableDisable : MonoBehaviour{
|
||||
|
||||
public bool pressed;
|
||||
bool alreadyPressed;
|
||||
|
||||
[Space]
|
||||
public Transform pressPos;
|
||||
public float pressRadius;
|
||||
public LayerMask whatIsPlayer;
|
||||
bool press;
|
||||
|
||||
[Space]
|
||||
public GameObject[] enable;
|
||||
public GameObject[] disable;
|
||||
public BoxCollider2D[] colliders;
|
||||
|
||||
[Space]
|
||||
public Sprite enabledState;
|
||||
public Sprite disabledState;
|
||||
|
||||
SpriteRenderer sprite;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
sprite = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (pressed && !alreadyPressed){
|
||||
if(enable != null){
|
||||
foreach(GameObject o in enable){
|
||||
o.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (disable != null){
|
||||
foreach (GameObject o in disable){
|
||||
o.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(BoxCollider2D col in colliders){
|
||||
col.enabled = false;
|
||||
}
|
||||
|
||||
sprite.sprite = disabledState;
|
||||
alreadyPressed = true;
|
||||
}else if(!alreadyPressed){
|
||||
press = Physics2D.OverlapCircle(pressPos.position, pressRadius, whatIsPlayer);
|
||||
if (press){
|
||||
pressed = true;
|
||||
}
|
||||
sprite.sprite = enabledState;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawWireSphere(pressPos.position, pressRadius);
|
||||
}
|
||||
}
|
11
Assets/Scripts/ButtonEnableDisable.cs.meta
Normal file
11
Assets/Scripts/ButtonEnableDisable.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6266cf5e24587da4a9fb9ce0908cb327
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
98
Assets/Scripts/EnemyController.cs
Normal file
98
Assets/Scripts/EnemyController.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyController : MonoBehaviour{
|
||||
|
||||
public float speed;
|
||||
Vector2 velocity = Vector2.zero;
|
||||
[Range(0, .3f)] public float movementSmoothing = .1f;
|
||||
public GameObject bloodExplosion;
|
||||
|
||||
public float turnTime;
|
||||
float time;
|
||||
float horizontalFacing = 1;
|
||||
|
||||
GameObject player;
|
||||
Rigidbody2D rb2d;
|
||||
|
||||
[Space]
|
||||
public Transform boxDetectionPos;
|
||||
public LayerMask whatIsPlayer;
|
||||
public float boxDetectionSize;
|
||||
bool playerDetected;
|
||||
bool detectPlayer;
|
||||
|
||||
[Space]
|
||||
public Animator anim;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
bool dead;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (!playerDetected){
|
||||
time += Time.deltaTime;
|
||||
if (time >= turnTime){
|
||||
horizontalFacing *= -1;
|
||||
Flip(horizontalFacing);
|
||||
time = 0;
|
||||
}
|
||||
|
||||
detectPlayer = Physics2D.OverlapCircle(boxDetectionPos.position, boxDetectionSize, whatIsPlayer);
|
||||
if (detectPlayer){
|
||||
anim.SetBool("Running", true);
|
||||
playerDetected = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(Mathf.Abs(player.transform.position.x - transform.position.x) >= .1f ){
|
||||
Flip(Mathf.RoundToInt(Mathf.Clamp((player.transform.position.x - transform.position.x) * 100, -1f, 1f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (player != null && playerDetected && !dead){
|
||||
Vector2 targetVelocity = new Vector2(Mathf.RoundToInt(Mathf.Clamp(player.transform.position.x - transform.position.x, -1f, 1f)) * speed, rb2d.velocity.y);
|
||||
rb2d.velocity = Vector2.SmoothDamp(rb2d.velocity, targetVelocity, ref velocity, movementSmoothing);
|
||||
}
|
||||
}
|
||||
|
||||
void Flip(float h){
|
||||
transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * h, transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
|
||||
public void WhoIsPlayer(GameObject player){
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void Die(){
|
||||
GetComponent<CapsuleCollider2D>().isTrigger = true;
|
||||
rb2d.velocity = Vector2.zero;
|
||||
rb2d.AddForce(new Vector2(-horizontalFacing * 10, 15), ForceMode2D.Impulse);
|
||||
Invoke("DeathExplode", 1);
|
||||
anim.SetTrigger("Die");
|
||||
dead = true;
|
||||
}
|
||||
|
||||
void DeathExplode(){
|
||||
Instantiate(bloodExplosion, transform.position, Quaternion.identity);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.gameObject.tag == "InstantDeath"){
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(boxDetectionPos.position, boxDetectionSize);
|
||||
}
|
||||
}
|
11
Assets/Scripts/EnemyController.cs.meta
Normal file
11
Assets/Scripts/EnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 171dbc9912c4f7e4298f16ad81b0152e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/Scripts/Paralax.cs
Normal file
15
Assets/Scripts/Paralax.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Paralax : MonoBehaviour{
|
||||
|
||||
[SerializeField] GameObject reference;
|
||||
[SerializeField] float scroll;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
Vector2 pos = new Vector2(reference.transform.position.x * scroll, transform.position.y * .05f);
|
||||
transform.position = pos;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Paralax.cs.meta
Normal file
11
Assets/Scripts/Paralax.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 73305d7e33efc7a46a3e3970a7f4150a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
240
Assets/Scripts/PlayerController.cs
Normal file
240
Assets/Scripts/PlayerController.cs
Normal file
|
@ -0,0 +1,240 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class PlayerController : MonoBehaviour{
|
||||
|
||||
EnemyController[] enemies;
|
||||
public SceneLoader sceneLoader;
|
||||
|
||||
public bool active;
|
||||
public GameObject otherPlayer;
|
||||
|
||||
[Space]
|
||||
public GameObject bloodExplosion;
|
||||
|
||||
[Space]
|
||||
public float shootSpeed = 2;
|
||||
public GameObject spiritPrefab;
|
||||
public float spawnOffset;
|
||||
|
||||
[Space]
|
||||
public CinemachineVirtualCamera vCam;
|
||||
|
||||
[Space]
|
||||
public float speed;
|
||||
[Range(0, .3f)] public float movementSmoothing = .05f;
|
||||
float horizontalMove;
|
||||
Vector2 velocity = Vector2.zero;
|
||||
|
||||
[Header("Jump")]
|
||||
public float jumpForce;
|
||||
public float fallMultiplier = 2.5f;
|
||||
public float lowJumpMultiplier = 2f;
|
||||
float gravityScale;
|
||||
|
||||
[Range(0, .3f)] public float jumpPressedRememberTime;
|
||||
float jumpPressedRemember;
|
||||
[Range(0, .3f)] public float groundedRememberTime;
|
||||
float groundedRemember;
|
||||
|
||||
public Transform feetPos;
|
||||
[Range(0, .5f)] public float feetRadius;
|
||||
public LayerMask whatIsGround;
|
||||
bool isGrounded;
|
||||
bool wasGrounded;
|
||||
bool jump;
|
||||
|
||||
[Header("Bounce")]
|
||||
public float bounceForce;
|
||||
public LayerMask whatIsBouncing;
|
||||
public float playerBounceForce;
|
||||
public LayerMask whatIsPlayerBouncing;
|
||||
bool bouncing;
|
||||
|
||||
[Space]
|
||||
public Animator anim;
|
||||
public Animator bounce;
|
||||
public Animator lightController;
|
||||
|
||||
Rigidbody2D rb2d;
|
||||
|
||||
void Awake(){
|
||||
enemies = FindObjectsOfType<EnemyController>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
gravityScale = rb2d.gravityScale;
|
||||
lightController.SetBool("Enabled", active);
|
||||
}
|
||||
|
||||
bool canMove;
|
||||
int h;
|
||||
bool wasActive;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(active && !wasActive){
|
||||
foreach(EnemyController e in enemies){
|
||||
e.WhoIsPlayer(gameObject);
|
||||
}
|
||||
wasActive = true;
|
||||
}
|
||||
|
||||
if (canMove){
|
||||
horizontalMove = Input.GetAxis("Horizontal") * speed;
|
||||
|
||||
if (Input.GetAxisRaw("Horizontal") != 0){
|
||||
Flip(Input.GetAxisRaw("Horizontal"));
|
||||
h = Mathf.RoundToInt(Input.GetAxisRaw("Horizontal"));
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("Fire1")){
|
||||
ShootSpirit((h == 0) ? 1 : h);
|
||||
}
|
||||
}else{
|
||||
horizontalMove = 0;
|
||||
}
|
||||
|
||||
isGrounded = Physics2D.OverlapCircle(feetPos.position, feetRadius, whatIsGround);
|
||||
anim.SetBool("Grounded", isGrounded);
|
||||
|
||||
if (active){
|
||||
canMove = true;
|
||||
lightController.SetBool("Enabled", true);
|
||||
}else{
|
||||
canMove = false;
|
||||
lightController.SetBool("Enabled", false);
|
||||
}
|
||||
|
||||
#region Jump
|
||||
if (isGrounded && !wasGrounded){
|
||||
bounce.SetTrigger("Bounce");
|
||||
wasGrounded = true;
|
||||
}else if (!isGrounded){
|
||||
wasGrounded = false;
|
||||
}
|
||||
|
||||
jumpPressedRemember -= Time.deltaTime;
|
||||
if (Input.GetButtonDown("Jump")){
|
||||
jumpPressedRemember = jumpPressedRememberTime;
|
||||
}
|
||||
|
||||
groundedRemember -= Time.deltaTime;
|
||||
if (isGrounded){
|
||||
groundedRemember = groundedRememberTime;
|
||||
bouncing = false;
|
||||
}
|
||||
|
||||
if ((jumpPressedRemember > 0) && (groundedRemember > 0)){
|
||||
if (canMove){
|
||||
jump = true;
|
||||
jumpPressedRemember = 0;
|
||||
groundedRemember = 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
bool isBouncing = Physics2D.OverlapCircle(feetPos.position, feetRadius, whatIsBouncing);
|
||||
|
||||
if (isBouncing){
|
||||
Jump(bounceForce);
|
||||
bouncing = true;
|
||||
isBouncing = false;
|
||||
}
|
||||
|
||||
bool isPlayerBouncing = Physics2D.OverlapCircle(feetPos.position, feetRadius, whatIsPlayerBouncing);
|
||||
|
||||
if (isPlayerBouncing){
|
||||
Jump(playerBounceForce);
|
||||
otherPlayer.GetComponent<PlayerController>().PlayBounceAnimation();
|
||||
bouncing = true;
|
||||
isBouncing = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
Vector2 targetVelocity = new Vector2(horizontalMove, rb2d.velocity.y);
|
||||
rb2d.velocity = Vector2.SmoothDamp(rb2d.velocity, targetVelocity, ref velocity, movementSmoothing);
|
||||
anim.SetFloat("Velocity", Mathf.Abs(rb2d.velocity.x));
|
||||
|
||||
#region Jump
|
||||
if(!bouncing && canMove){
|
||||
if (rb2d.velocity.y < 0){
|
||||
rb2d.gravityScale = fallMultiplier * gravityScale;
|
||||
}else if (rb2d.velocity.y > 0 && !Input.GetButton("Jump")){
|
||||
rb2d.gravityScale = lowJumpMultiplier * gravityScale;
|
||||
}else{
|
||||
rb2d.gravityScale = gravityScale;
|
||||
}
|
||||
}
|
||||
|
||||
if (jump){
|
||||
Jump(jumpForce);
|
||||
jump = false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public void PlayBounceAnimation(){
|
||||
bounce.SetTrigger("Bounce");
|
||||
}
|
||||
|
||||
void Jump(float force){
|
||||
bounce.SetTrigger("Bounce");
|
||||
rb2d.velocity = new Vector2(rb2d.velocity.x, 0);
|
||||
rb2d.AddForce(Vector2.up * force, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
void Flip(float h){
|
||||
transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * h, transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
|
||||
void ShootSpirit(int direction){
|
||||
var spirit = Instantiate(spiritPrefab, transform.position, transform.rotation);
|
||||
Rigidbody2D rigidbody = spirit.GetComponent<Rigidbody2D>();
|
||||
|
||||
spirit.transform.position += new Vector3(spawnOffset * direction, 0, 0);
|
||||
rigidbody.AddForce(new Vector2(shootSpeed * direction, 5), ForceMode2D.Impulse);
|
||||
|
||||
vCam.Follow = spirit.transform;
|
||||
spirit.GetComponent<SpiritBall>().SetCamera(vCam, GetComponent<PlayerController>());
|
||||
|
||||
foreach(EnemyController e in enemies){
|
||||
e.WhoIsPlayer(null);
|
||||
}
|
||||
wasActive = false;
|
||||
active = false;
|
||||
}
|
||||
|
||||
void Die(){
|
||||
Instantiate(bloodExplosion, transform.position, Quaternion.identity);
|
||||
sceneLoader.LoadScene(0);
|
||||
gameObject.SetActive(false);
|
||||
otherPlayer.SetActive(false);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.gameObject.tag == "InstantDeath"){
|
||||
Die();
|
||||
}
|
||||
if(col.gameObject.tag == "Win"){
|
||||
Time.timeScale = 0;
|
||||
sceneLoader.LoadScene(0);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.tag == "Enemy"){
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(feetPos.position, feetRadius);
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21a3de7d73bb07b42afd7f9970590aee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/ScreenshakeHandler.cs
Normal file
35
Assets/Scripts/ScreenshakeHandler.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class ScreenshakeHandler : MonoBehaviour{
|
||||
|
||||
[SerializeField] private CinemachineVirtualCamera cam;
|
||||
private static CinemachineBasicMultiChannelPerlin noise;
|
||||
|
||||
private static float timer = 0;
|
||||
|
||||
void Start(){
|
||||
noise = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0){
|
||||
timer = 0;
|
||||
noise.m_AmplitudeGain = 0;
|
||||
noise.m_FrequencyGain = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void AddScreenShake(float amplitude, float frequency, float duration){
|
||||
//Prevents small shakes from overriding big ones
|
||||
if (amplitude < noise.m_AmplitudeGain || frequency < noise.m_FrequencyGain) return;
|
||||
|
||||
noise.m_AmplitudeGain = amplitude;
|
||||
noise.m_FrequencyGain = frequency;
|
||||
timer = duration;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ScreenshakeHandler.cs.meta
Normal file
11
Assets/Scripts/ScreenshakeHandler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 333dce12099166a44acdd3d6f1d42661
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
69
Assets/Scripts/SpiritBall.cs
Normal file
69
Assets/Scripts/SpiritBall.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class SpiritBall : MonoBehaviour{
|
||||
|
||||
public float spiritballLifeTime = 2f;
|
||||
|
||||
public GameObject particles;
|
||||
public float particleLifetime = 1f;
|
||||
|
||||
public GameObject deathEffectPrefab;
|
||||
public float deathEffectLifetime;
|
||||
|
||||
CinemachineVirtualCamera vCam;
|
||||
PlayerController player;
|
||||
bool playerCollided;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
Invoke("DestroyFireball", spiritballLifeTime);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
void DestroyFireball(){
|
||||
ScreenshakeHandler.AddScreenShake(3, 5, .1f);
|
||||
|
||||
particles.transform.parent = null;
|
||||
particles.GetComponent<ParticleSystem>().Stop();
|
||||
Destroy(particles, particleLifetime);
|
||||
|
||||
var deathEffect = Instantiate(deathEffectPrefab, transform.position, transform.rotation);
|
||||
Destroy(deathEffect, deathEffectLifetime);
|
||||
|
||||
if (!playerCollided){
|
||||
player.active = true;
|
||||
vCam.Follow = player.gameObject.transform;
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void SetCamera(CinemachineVirtualCamera camera, PlayerController from){
|
||||
vCam = camera;
|
||||
player = from;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.tag == "Player"){
|
||||
vCam.Follow = col.gameObject.transform;
|
||||
col.gameObject.GetComponent<PlayerController>().active = true;
|
||||
playerCollided = true;
|
||||
CancelInvoke("DestroyFireball");
|
||||
DestroyFireball();
|
||||
}
|
||||
|
||||
if(col.gameObject.tag == "Enemy"){
|
||||
vCam.Follow = col.gameObject.transform;
|
||||
col.gameObject.GetComponent<EnemyController>().Die();
|
||||
CancelInvoke("DestroyFireball");
|
||||
DestroyFireball();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SpiritBall.cs.meta
Normal file
11
Assets/Scripts/SpiritBall.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5da7de308b94e5b4db2a1344fc5b8be4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
70
Assets/Scripts/Thunder.cs
Normal file
70
Assets/Scripts/Thunder.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Thunder : MonoBehaviour{
|
||||
|
||||
[SerializeField] private Camera camera;
|
||||
[SerializeField] private UnityEngine.Experimental.Rendering.Universal.Light2D globalLight;
|
||||
[SerializeField] private Color lightingColor;
|
||||
[SerializeField] private AudioSource thunderSound;
|
||||
|
||||
[SerializeField] private float intervalTime = 5f;
|
||||
|
||||
private Color orgLightColor;
|
||||
private Color orgCamBGColor;
|
||||
private float orgIntensity;
|
||||
|
||||
private float timer;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
orgLightColor = globalLight.color;
|
||||
orgIntensity = globalLight.intensity;
|
||||
orgCamBGColor = camera.backgroundColor;
|
||||
|
||||
timer = intervalTime;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0){
|
||||
LightningStrike();
|
||||
timer = intervalTime + Random.Range(-intervalTime * 0.3f, intervalTime * 0.3f);
|
||||
}
|
||||
|
||||
if (globalLight.intensity > orgIntensity){
|
||||
globalLight.intensity -= Time.deltaTime * 2.5f;
|
||||
camera.backgroundColor = Color.Lerp(camera.backgroundColor, orgCamBGColor, Mathf.PingPong(Time.time, 0.2f));
|
||||
}else{
|
||||
ResetLights();
|
||||
}
|
||||
}
|
||||
|
||||
private void LightningStrike(){
|
||||
ScreenshakeHandler.AddScreenShake(5, 5, 0.5f);
|
||||
|
||||
//thunderSound.pitch = Random.Range(0.5f, 1f);
|
||||
//thunderSound.Play();
|
||||
|
||||
globalLight.color = lightingColor;
|
||||
camera.backgroundColor = lightingColor;
|
||||
globalLight.intensity = 1.25f;
|
||||
//Invoke("MiniStrike", 0.05f);
|
||||
Invoke("MiniStrike", 0.15f);
|
||||
// Invoke("ResetLights", 2.25f);
|
||||
}
|
||||
|
||||
private void MiniStrike(){
|
||||
globalLight.color = lightingColor;
|
||||
// camera.backgroundColor = lightingColor;
|
||||
globalLight.intensity = 1f;
|
||||
}
|
||||
|
||||
private void ResetLights(){
|
||||
globalLight.color = orgLightColor;
|
||||
camera.backgroundColor = orgCamBGColor;
|
||||
globalLight.intensity = orgIntensity;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Thunder.cs.meta
Normal file
11
Assets/Scripts/Thunder.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 621381ec9cd54c946829c5371ef6437d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue