Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class LayerManager : MonoBehaviour
- {
- public static LayerMask WhatIsGround;
- private SpriteRenderer m_SpriteRenderer;
- private GameObject m_Obj;
- [SerializeField] private float m_Timer;
- private Sprite[] sprites;
- [SerializeField] private float time;
- private void Start()
- {
- m_Obj = gameObject;
- m_SpriteRenderer = GetComponent<SpriteRenderer>();
- }
- public enum LayerState
- {
- Default,
- Red,
- Blue,
- Yellow,
- Green,
- }
- public LayerState layers;
- // Update is called once per frame
- private void Update()
- {
- if (m_Timer > 0)
- {
- m_Timer -= 1 * Time.deltaTime;
- }
- else
- {
- //layers = LayerState.Default;
- }
- switch (layers)
- {
- case LayerState.Default:
- SetState(0, "Ground", null, Color.white);
- break;
- case LayerState.Red:
- SetState(6, "Ground", "Red", Color.red);
- break;
- case LayerState.Blue:
- SetState(7, "Ground", "Blue", Color.blue);
- break;
- case LayerState.Yellow:
- SetState(8, "Ground", "Yellow", Color.yellow);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- // Colliding with Crystals to change players Layer
- switch (other.tag)
- {
- // If we collide with objects with the RedCrystal tag
- case "RedCrystal":
- // Change our LayerState to red
- layers = LayerState.Red;
- ResetTime();
- break;
- case "BlueCrystal":
- layers = LayerState.Blue;
- ResetTime();
- break;
- case "YellowCrystal":
- layers = LayerState.Yellow;
- ResetTime();
- break;
- case "Enemy":
- layers = LayerState.Default;
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- private void SetState(int layer, string layer1, string layer2, Color color)
- {
- print((int)layers);
- // Set the objects Player to the correct Phsycis Layer
- m_Obj.layer = layer;
- // Change whatisGround so that you only can jump on what you can interact with
- WhatIsGround = LayerMask.GetMask(layer1, layer2);
- // Change the colour of the sprite to reflect the colour of the layer
- m_SpriteRenderer.color = color;
- // Change the sprite to a different sprite to reflect the layer
- //m_SpriteRenderer.sprite = sprites[(int) layers];
- }
- private void ResetTime()
- {
- m_Timer += time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement