#30 Targeting and fire whit targetUI

This commit is contained in:
M1_IDMhan 2023-09-11 14:15:18 +09:00
parent c72b97cc61
commit 1a2f374fb5
8 changed files with 254 additions and 75 deletions

View File

@ -96912,12 +96912,30 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
power: 0 power: 0
reloadTime: 0 reloadTime: 1
radarTargetUI: {fileID: 0} radarTargetUI: {fileID: 0}
projectilePrefab: {fileID: 0} projectilePrefab: {fileID: 0}
launchPoint: {fileID: 0} launchPoint: {fileID: 0}
timeOfFlight: 1 timeOfFlight: 1
predictedPos: {fileID: 0} predictedPos: {fileID: 1287417561}
--- !u!1183024399 &619366763
LookAtConstraint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 619366757}
m_Enabled: 1
serializedVersion: 2
m_Weight: 1
m_RotationAtRest: {x: 0, y: 0, z: 0}
m_RotationOffset: {x: 0, y: 0, z: 0}
m_Roll: 0
m_WorldUpObject: {fileID: 0}
m_UseUpObject: 0
m_Active: 1
m_IsLocked: 0
m_Sources: []
--- !u!1 &619911013 --- !u!1 &619911013
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -97525,22 +97543,22 @@ PrefabInstance:
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.67404693 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.21176523 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.66609627 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.23902294 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
@ -97571,6 +97589,10 @@ PrefabInstance:
type: 3} type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 622062901} addedObject: {fileID: 622062901}
- targetCorrespondingSourceObject: {fileID: 4836829392273355565, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3}
insertIndex: -1
addedObject: {fileID: 622062904}
m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3}
--- !u!4 &622062898 stripped --- !u!4 &622062898 stripped
Transform: Transform:
@ -97591,12 +97613,30 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
power: 0 power: 0
reloadTime: 0 reloadTime: 1
radarTargetUI: {fileID: 0} radarTargetUI: {fileID: 0}
projectilePrefab: {fileID: 0} projectilePrefab: {fileID: 0}
launchPoint: {fileID: 0} launchPoint: {fileID: 0}
timeOfFlight: 1 timeOfFlight: 1
predictedPos: {fileID: 0} predictedPos: {fileID: 1287417561}
--- !u!1183024399 &622062904
LookAtConstraint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 598889757}
m_Enabled: 1
serializedVersion: 2
m_Weight: 1
m_RotationAtRest: {x: 0, y: 0, z: 0}
m_RotationOffset: {x: 0, y: 0, z: 0}
m_Roll: 0
m_WorldUpObject: {fileID: 0}
m_UseUpObject: 0
m_Active: 1
m_IsLocked: 0
m_Sources: []
--- !u!1 &622341546 --- !u!1 &622341546
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -98857,22 +98897,22 @@ PrefabInstance:
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.67404693 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.21176523 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.66609627 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.23902294 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
@ -98903,6 +98943,10 @@ PrefabInstance:
type: 3} type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 1910056923} addedObject: {fileID: 1910056923}
- targetCorrespondingSourceObject: {fileID: 4836829392273355565, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3}
insertIndex: -1
addedObject: {fileID: 1910056926}
m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3}
--- !u!4 &631284636 stripped --- !u!4 &631284636 stripped
Transform: Transform:
@ -197552,22 +197596,22 @@ PrefabInstance:
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.6661488 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.23903932 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.67399514 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.21174636 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
@ -197598,6 +197642,10 @@ PrefabInstance:
type: 3} type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 1647855425} addedObject: {fileID: 1647855425}
- targetCorrespondingSourceObject: {fileID: 4836829392273355565, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3}
insertIndex: -1
addedObject: {fileID: 1647855428}
m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3}
--- !u!4 &1260016380 stripped --- !u!4 &1260016380 stripped
Transform: Transform:
@ -258972,12 +259020,30 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
power: 0 power: 0
reloadTime: 0 reloadTime: 1
radarTargetUI: {fileID: 0} radarTargetUI: {fileID: 0}
projectilePrefab: {fileID: 0} projectilePrefab: {fileID: 0}
launchPoint: {fileID: 0} launchPoint: {fileID: 0}
timeOfFlight: 1 timeOfFlight: 1
predictedPos: {fileID: 0} predictedPos: {fileID: 1287417561}
--- !u!1183024399 &1647855428
LookAtConstraint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1647855422}
m_Enabled: 1
serializedVersion: 2
m_Weight: 1
m_RotationAtRest: {x: 0, y: 0, z: 0}
m_RotationOffset: {x: 0, y: 0, z: 0}
m_Roll: 0
m_WorldUpObject: {fileID: 0}
m_UseUpObject: 0
m_Active: 1
m_IsLocked: 0
m_Sources: []
--- !u!1 &1648071599 --- !u!1 &1648071599
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -289190,7 +289256,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1871370245} m_GameObject: {fileID: 1871370245}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0.6764068, y: -0, z: -0, w: 0.7365283} m_LocalRotation: {x: 0.67640686, y: -0.0000002980232, z: 0.0000002980232, w: 0.7365283}
m_LocalPosition: {x: -0.0000002384187, y: 120, z: -10.000001} m_LocalPosition: {x: -0.0000002384187, y: 120, z: -10.000001}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
@ -294324,12 +294390,30 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
power: 0 power: 0
reloadTime: 0 reloadTime: 1
radarTargetUI: {fileID: 0} radarTargetUI: {fileID: 0}
projectilePrefab: {fileID: 0} projectilePrefab: {fileID: 0}
launchPoint: {fileID: 0} launchPoint: {fileID: 0}
timeOfFlight: 1 timeOfFlight: 1
predictedPos: {fileID: 0} predictedPos: {fileID: 1287417561}
--- !u!1183024399 &1910056926
LookAtConstraint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910056920}
m_Enabled: 1
serializedVersion: 2
m_Weight: 1
m_RotationAtRest: {x: 0, y: 0, z: 0}
m_RotationOffset: {x: 0, y: 0, z: 0}
m_Roll: 0
m_WorldUpObject: {fileID: 0}
m_UseUpObject: 0
m_Active: 1
m_IsLocked: 0
m_Sources: []
--- !u!1 &1911764924 --- !u!1 &1911764924
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -323077,6 +323161,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_persistent: 0 _persistent: 0
<RadarTargetUis>k__BackingField: []
--- !u!1 &2105084994 --- !u!1 &2105084994
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -328992,7 +329077,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6b9354e94ca0743c98216572c03343d5, type: 3} m_Script: {fileID: 11500000, guid: 6b9354e94ca0743c98216572c03343d5, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
<RotationSpeed>k__BackingField: -60 <RotationSpeed>k__BackingField: -30
--- !u!1001 &2685185313231177978 --- !u!1001 &2685185313231177978
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -329019,22 +329104,22 @@ PrefabInstance:
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.6661488 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.23903932 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.67399514 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.21174636 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a, - target: {fileID: 2155776711209515616, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3} type: 3}
@ -329065,6 +329150,10 @@ PrefabInstance:
type: 3} type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 619366760} addedObject: {fileID: 619366760}
- targetCorrespondingSourceObject: {fileID: 4836829392273355565, guid: 8c9e74631c8994b8cb728cde8efae49a,
type: 3}
insertIndex: -1
addedObject: {fileID: 619366763}
m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8c9e74631c8994b8cb728cde8efae49a, type: 3}
--- !u!1 &3000142793521421624 --- !u!1 &3000142793521421624
GameObject: GameObject:

View File

@ -1,6 +1,9 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using Blobcreate.ProjectileToolkit; using Blobcreate.ProjectileToolkit;
using UnityEngine; using UnityEngine;
using UnityEngine.Animations;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace BlueWaterProject namespace BlueWaterProject
@ -8,9 +11,12 @@ namespace BlueWaterProject
public class Canon : MonoBehaviour public class Canon : MonoBehaviour
{ {
public float power; public float power;
public float reloadTime; public float reloadTime = 1f;
public GameObject radarTargetUI; public RadarTargetUI radarTargetUI;
private bool isReloading;
private LookAtConstraint canonLookAtConstraint;
public Rigidbody projectilePrefab; public Rigidbody projectilePrefab;
public Transform launchPoint; public Transform launchPoint;
public float timeOfFlight = 1f; public float timeOfFlight = 1f;
@ -20,18 +26,47 @@ namespace BlueWaterProject
{ {
projectilePrefab = DataManager.Inst.grenadeFire.GetComponent<Rigidbody>(); projectilePrefab = DataManager.Inst.grenadeFire.GetComponent<Rigidbody>();
launchPoint = transform.Find("FirePoint"); launchPoint = transform.Find("FirePoint");
canonLookAtConstraint = GetComponent<LookAtConstraint>();
} }
private void Awake() private void Awake()
{ {
Init(); Init();
} }
private void Update()
{
if (!radarTargetUI.gameObject.activeInHierarchy && !isReloading)
{
StartCoroutine(ReloadCoroutine());
}
}
private IEnumerator ReloadCoroutine()
{
isReloading = true;
yield return new WaitForSeconds(reloadTime);
radarTargetUI.Reactivate();
isReloading = false;
}
public void Fire() public void Fire()
{ {
var myRigid = Instantiate(projectilePrefab, launchPoint.position, launchPoint.rotation); var myRigid = Instantiate(projectilePrefab, launchPoint.position, launchPoint.rotation);
var v = Projectile.VelocityByTime(myRigid.transform.position, predictedPos.position, timeOfFlight); var v = Projectile.VelocityByTime(myRigid.transform.position, predictedPos.position, timeOfFlight);
myRigid.AddForce(v, ForceMode.VelocityChange); myRigid.AddForce(v, ForceMode.VelocityChange);
} }
public void LookAtTarget()
{
canonLookAtConstraint.SetSources(new List<ConstraintSource>
{
new ConstraintSource
{
sourceTransform = predictedPos,
weight = 1
}
});
}
} }
} }

View File

@ -35,6 +35,8 @@ namespace BlueWaterProject
public Collider[] radar = new Collider[10]; public Collider[] radar = new Collider[10];
public Transform[] inCameraRadar = new Transform[10]; public Transform[] inCameraRadar = new Transform[10];
public Transform target; public Transform target;
// 클래스 레벨 변수
private List<Transform> visibleObjects;
[Title("캐논")] [Title("캐논")]
public Rigidbody projectilePrefab; public Rigidbody projectilePrefab;
@ -52,6 +54,8 @@ namespace BlueWaterProject
{ {
character = transform.Find("Character").gameObject; character = transform.Find("Character").gameObject;
rb = GetComponent<Rigidbody>(); rb = GetComponent<Rigidbody>();
GetComponentsInChildren(Canons);
visibleObjects = new List<Transform>();
} }
#region Unity Function #region Unity Function
@ -61,24 +65,17 @@ namespace BlueWaterProject
Init(); Init();
} }
private void Start()
{
CanonInit();
}
private void FixedUpdate() private void FixedUpdate()
{ {
if (IsInShipMode) HandleMovement();
{ }
MoveCharacterPlayer();
private void Update()
} {
else FindInRadarRange();
{ FilterInCameraObjects();
MoveShipPlayer(); FindTarget();
RotatePlayer(); LookAtTarget();
}
} }
#endregion #endregion
@ -111,6 +108,19 @@ namespace BlueWaterProject
character.transform.position += movement; character.transform.position += movement;
} }
private void HandleMovement()
{
if (IsInShipMode)
{
MoveCharacterPlayer();
}
else
{
MoveShipPlayer();
RotatePlayer();
}
}
#endregion #endregion
#region AssaultMode/DreadgeMode Switch #region AssaultMode/DreadgeMode Switch
@ -142,7 +152,7 @@ namespace BlueWaterProject
#region Interaction Key #region Interaction Key
private void OnInteractionE(InputValue value) private void OnInteractionE(InputValue value) //E
{ {
UiManager.Inst.CheckRadarOverlap(); UiManager.Inst.CheckRadarOverlap();
} }
@ -181,7 +191,7 @@ namespace BlueWaterProject
UiManager.Inst.AddCard(); UiManager.Inst.AddCard();
} }
#region TakeAim & Fire #region TakeAim
private void OnTakeAim(InputValue value) // Space private void OnTakeAim(InputValue value) // Space
{ {
@ -211,9 +221,48 @@ namespace BlueWaterProject
#endregion #endregion
private void CanonInit() #region CanonAndRader
private void FindInRadarRange()
{ {
GetComponentsInChildren(Canons); Physics.OverlapSphereNonAlloc(transform.position, GlobalValue.RADAR_RANGE, radar, LayerMask.GetMask(GlobalValue.ENEMY_LAYER));
} }
private void FilterInCameraObjects()
{
visibleObjects.Clear();
foreach (var col in radar)
{
if (col == null) continue;
var screenPoint = Camera.main.WorldToViewportPoint(col.transform.position);
if (screenPoint.z > 0 && screenPoint.x >= 0 && screenPoint.x <= 1 && screenPoint.y >= 0 && screenPoint.y <= 1)
{
visibleObjects.Add(col.transform);
}
}
visibleObjects.Sort((a, b) => Vector3.Distance(transform.position, a.position).CompareTo(Vector3.Distance(transform.position, b.position)));
}
private void FindTarget()
{
foreach (var trans in visibleObjects)
{
if (trans.Find("TestTarget") == null) continue;
target = trans.Find("TestTarget").transform;
break;
}
}
private void LookAtTarget()
{
if (target == null) return;
foreach (var canon in Canons)
{
canon.predictedPos = target;
canon.LookAtTarget();
}
}
#endregion
} }
} }

View File

@ -11,11 +11,9 @@ namespace BlueWaterProject
public float RotationSpeed { get; set; } public float RotationSpeed { get; set; }
private float currentRotationZ = 0f; private float currentRotationZ = 0f;
private void Update() private void FixedUpdate()
{ {
currentRotationZ += RotationSpeed * Time.deltaTime; transform.Rotate(0, 0, RotationSpeed * Time.deltaTime);
currentRotationZ = currentRotationZ % 360; // 360을 초과하지 않도록
transform.eulerAngles = new Vector3(0, 0, currentRotationZ);
} }
} }
} }

View File

@ -1,3 +1,4 @@
using System.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -12,6 +13,7 @@ namespace BlueWaterProject
private void OnEnable() private void OnEnable()
{ {
Image = GetComponent<Image>(); Image = GetComponent<Image>();
transform.rotation = Quaternion.Euler(0, 0, RotationZ + Image.fillAmount * -180);
} }
private void Update() private void Update()
@ -29,5 +31,11 @@ namespace BlueWaterProject
RotationZ = rotation; RotationZ = rotation;
Image.fillAmount = fillAmount; Image.fillAmount = fillAmount;
} }
public void Reactivate()
{
RadarTargetInit(Random.Range(0f, 360f), Random.Range(0.1f, 0.2f));
transform.gameObject.SetActive(true);
}
} }
} }

View File

@ -23,7 +23,7 @@ namespace BlueWaterProject
[Title("Radar")] [Title("Radar")]
private Transform radar; private Transform radar;
private Transform radarTargets; private Transform radarTargets;
public List<RadarTargetUI> RadarTargetUis { get; } = new (GlobalValue.MAX_CANON_COUNT); [field: SerializeField] public List<RadarTargetUI> RadarTargetUis { get; private set; } = new (GlobalValue.MAX_CANON_COUNT);
public RadarNeedle RadarNeedle { get; private set; } public RadarNeedle RadarNeedle { get; private set; }
@ -49,10 +49,7 @@ namespace BlueWaterProject
CursorTextureChange(); CursorTextureChange();
AssaultCardInit(); AssaultCardInit();
for (var i = 0; i < GameManager.Inst.player.Canons.Count; i++) RadarTargetInit();
{
RadarTargetInit();
}
} }
public void AddCard() //TODO Test button and function, delete later public void AddCard() //TODO Test button and function, delete later
@ -87,10 +84,14 @@ namespace BlueWaterProject
public void RadarTargetInit() public void RadarTargetInit()
{ {
var obj = Instantiate(DataManager.Inst.radarTargetUi, radarTargets); for (var i = 0; i < GameManager.Inst.player.Canons.Count; i++)
var radarTargetUi = obj.GetComponent<RadarTargetUI>(); {
radarTargetUi.RadarTargetInit(Random.Range(0f, 360f), Random.Range(0.1f, 0.2f)); var obj = Instantiate(DataManager.Inst.radarTargetUi, radarTargets);
RadarTargetUis.Add(radarTargetUi); var radarTargetUi = obj.GetComponent<RadarTargetUI>();
radarTargetUi.RadarTargetInit(Random.Range(0f, 360f), Random.Range(0.1f, 0.2f));
RadarTargetUis.Add(radarTargetUi);
GameManager.Inst.player.Canons[i].radarTargetUI = radarTargetUi;
}
} }
public void CheckRadarOverlap() public void CheckRadarOverlap()
@ -100,24 +101,21 @@ namespace BlueWaterProject
for (var i = 0; i < RadarTargetUis.Count; i++) for (var i = 0; i < RadarTargetUis.Count; i++)
{ {
var radarTargetUI = RadarTargetUis[i]; var radarTargetUI = RadarTargetUis[i];
var startAngle = radarTargetUI.RotationZ; var canon = GameManager.Inst.player.Canons[i];
var endAngle = radarTargetUI.RotationZ + radarTargetUI.Image.fillAmount * 360f; var startAngle = radarTargetUI.RotationZ - radarTargetUI.Image.fillAmount * 180f;
var endAngle = radarTargetUI.RotationZ + radarTargetUI.Image.fillAmount * 180f;
// 각도 비교 및 허용 오차 추가 if (!IsOverlap(needleRotationZ, startAngle, endAngle, GlobalValue.RADAR_OVERLAP_TOLERANCE)) continue;
if (IsOverlap(needleRotationZ, startAngle, endAngle, GlobalValue.RADAR_OVERLAP_TOLERANCE)) // 5도의 오차 허용 if (!radarTargetUI.gameObject.activeSelf) continue;
{ radarTargetUI.gameObject.SetActive(false);
radarTargetUI.gameObject.SetActive(false); canon.Fire();
}
} }
} }
private bool IsOverlap(float needleRotation, float startAngle, float endAngle, float tolerance = 0) private bool IsOverlap(float needleRotation, float startAngle, float endAngle, float tolerance = 0)
{ {
// 오프셋 보정 예시 var correctedNeedleRotation = needleRotation;
var correctedNeedleRotation = needleRotation + 36;
return correctedNeedleRotation >= (startAngle - tolerance) && correctedNeedleRotation <= (endAngle + tolerance); return correctedNeedleRotation >= (startAngle - tolerance) && correctedNeedleRotation <= (endAngle + tolerance);
} }
} }
} }

View File

@ -15,6 +15,8 @@ namespace BlueWaterProject
/// <summary> Radar 바늘이 레이더에 겹치는 허용 범위 </summary> /// <summary> Radar 바늘이 레이더에 겹치는 허용 범위 </summary>
public const float RADAR_OVERLAP_TOLERANCE = 5f; public const float RADAR_OVERLAP_TOLERANCE = 5f;
public const float RADAR_RANGE = 100f;
public const string ENEMY_LAYER = "Enemy";
public enum UnitType public enum UnitType
{ {

View File

@ -59,7 +59,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_Color: {r: 1, g: 0.9263606, b: 0, a: 0.39215687} m_Color: {r: 1, g: 0.92549026, b: 0, a: 0.39215687}
m_RaycastTarget: 1 m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1 m_Maskable: 1