From fb8eee4bdc6d01eb859a8582181a7c82852d031f Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:04:26 +0100 Subject: [PATCH] Cameras now follows players --- Assets/Scenes/GameScene.unity | 42 +++++++++++++++++-- Assets/Scripts/CameraScripts.meta | 8 ++++ .../Scripts/CameraScripts/SetupCinemachine.cs | 24 +++++++++++ .../CameraScripts/SetupCinemachine.cs.meta | 2 + 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/CameraScripts.meta create mode 100644 Assets/Scripts/CameraScripts/SetupCinemachine.cs create mode 100644 Assets/Scripts/CameraScripts/SetupCinemachine.cs.meta diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index bf9e5bc..b1388e6 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -334,6 +334,36 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &213238739 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2607936989766580656, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + m_PrefabInstance: {fileID: 5796191506433166633} + m_PrefabAsset: {fileID: 0} +--- !u!114 &213238741 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3401975006071930001, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + m_PrefabInstance: {fileID: 5796191506433166633} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 213238739} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e5eb80d8e62d9d145bb50fb783c0f731, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &213238742 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 213238739} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea37f4c45c451b44facf5123a931a3e9, type: 3} + m_Name: + m_EditorClassIdentifier: + targetbrain: {fileID: 213238741} + targetRadius: 3 --- !u!1 &438029675 GameObject: m_ObjectHideFlags: 0 @@ -3672,8 +3702,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cfcb795658e5b9d8bbbf6d6e238c21a0, type: 3} m_Name: m_EditorClassIdentifier: - ReviveParticleSystem: {fileID: 0} - ReviveText: {fileID: 0} + Players: [] --- !u!1001 &4158834148864819266 PrefabInstance: m_ObjectHideFlags: 0 @@ -3872,6 +3901,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 3401975006071930001, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + propertyPath: m_Targets.Array.size + value: 0 + objectReference: {fileID: 0} - target: {fileID: 3401975006071930001, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} propertyPath: m_Targets.Array.data[0].target value: @@ -3939,7 +3972,10 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 2607936989766580656, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + insertIndex: -1 + addedObject: {fileID: 213238742} m_SourcePrefab: {fileID: 100100000, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} --- !u!114 &5796191506433166634 stripped MonoBehaviour: diff --git a/Assets/Scripts/CameraScripts.meta b/Assets/Scripts/CameraScripts.meta new file mode 100644 index 0000000..1de3e5c --- /dev/null +++ b/Assets/Scripts/CameraScripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7ecabe8c21002eb41ac883a487281352 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CameraScripts/SetupCinemachine.cs b/Assets/Scripts/CameraScripts/SetupCinemachine.cs new file mode 100644 index 0000000..fcbc537 --- /dev/null +++ b/Assets/Scripts/CameraScripts/SetupCinemachine.cs @@ -0,0 +1,24 @@ +using Cinemachine; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +public class SetupCinemachine : MonoBehaviour +{ + public CinemachineTargetGroup targetbrain; + [SerializeField] private float targetRadius = 3f; + + private void OnEnable() + { + GameManager.OnPlayersReady += OnPlayersReady; + } + + private void OnPlayersReady(GameObject[] players) + { + var targets = players.Select(x => new CinemachineTargetGroup.Target { target = x.transform, weight = 1, radius = targetRadius }).ToArray(); + + targetbrain.m_Targets = targets; + } +} diff --git a/Assets/Scripts/CameraScripts/SetupCinemachine.cs.meta b/Assets/Scripts/CameraScripts/SetupCinemachine.cs.meta new file mode 100644 index 0000000..654ae63 --- /dev/null +++ b/Assets/Scripts/CameraScripts/SetupCinemachine.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ea37f4c45c451b44facf5123a931a3e9 \ No newline at end of file