Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

3 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5. using UnityEngine.UI;
  6. public class PlayerJoinIcon : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private Image m_apron;
  10. private PlayerData m_data;
  11. private Vector3 m_startingScale;
  12. private void OnEnable()
  13. {
  14. m_startingScale = transform.localScale;
  15. Debug.Log("New player awake");
  16. if (m_data != null)
  17. {
  18. m_data.Input.currentActionMap.FindAction("Ping").started += OnPlayerPing;
  19. m_data.Input.currentActionMap.FindAction("Ping").canceled += OnPlayerPing;
  20. }
  21. }
  22. private void OnDisable()
  23. {
  24. if (m_data != null)
  25. {
  26. m_data.Input.currentActionMap.FindAction("Ping").started -= OnPlayerPing;
  27. m_data.Input.currentActionMap.FindAction("Ping").canceled -= OnPlayerPing;
  28. }
  29. }
  30. public void Initialise(PlayerData data)
  31. {
  32. Debug.Log("Initialised new Player");
  33. m_data = data;
  34. m_apron.color = data.Color;
  35. }
  36. public void OnPlayerPing(InputAction.CallbackContext args)
  37. {
  38. Debug.Log($"Ping: {args.phase}");
  39. if (args.phase == InputActionPhase.Started)
  40. transform.localScale = m_startingScale * 1.1f;
  41. else if (args.phase == InputActionPhase.Canceled)
  42. transform.localScale = m_startingScale;
  43. }
  44. }