CameraMagnetTargetController.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Cinemachine;
  4. using UnityEngine;
  5. public class CameraMagnetTargetController : MonoBehaviour
  6. {
  7. public CinemachineTargetGroup targetGroup;
  8. private int playerIndex;
  9. private CameraMagnetProperty[] cameraMagnets;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. cameraMagnets = GetComponentsInChildren<CameraMagnetProperty>();
  14. playerIndex = 0;
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. for (int i = 1; i < targetGroup.m_Targets.Length; ++i)
  20. {
  21. float distance = (targetGroup.m_Targets[playerIndex].target.position -
  22. targetGroup.m_Targets[i].target.position).magnitude;
  23. if (distance < cameraMagnets[i-1].Proximity)
  24. {
  25. targetGroup.m_Targets[i].weight = cameraMagnets[i-1].MagnetStrength *
  26. (1 - (distance / cameraMagnets[i-1].Proximity));
  27. }
  28. else
  29. {
  30. targetGroup.m_Targets[i].weight = 0;
  31. }
  32. }
  33. }
  34. }