Weapons damages update if value change
This commit is contained in:
@@ -11,17 +11,21 @@ public class PlayerWeapons : MonoBehaviour
|
|||||||
[SerializeField] private GameObject arrow;
|
[SerializeField] private GameObject arrow;
|
||||||
|
|
||||||
private PlayerMovements _pm;
|
private PlayerMovements _pm;
|
||||||
|
private PlayerManager _manager;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
_pm = GetComponent<PlayerMovements>();
|
_pm = GetComponent<PlayerMovements>();
|
||||||
|
_manager = GetComponent<PlayerManager>();
|
||||||
|
|
||||||
InvokeRepeating(nameof(ShootBeam), 5f, 5f);
|
InvokeRepeating(nameof(ShootBeam), 5f, 5f);
|
||||||
InvokeRepeating(nameof(ShootArrow), 2f, 2f);
|
InvokeRepeating(nameof(ShootArrow), 2f, 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShootBeam()
|
private void ShootBeam()
|
||||||
{
|
{
|
||||||
Instantiate(laser, transform.position, _pm.lookOnRight ? Quaternion.identity : Quaternion.Euler(0, 0, 180), transform);
|
GameObject defaultBeam = Instantiate(laser, transform.position, _pm.lookOnRight ? Quaternion.identity : Quaternion.Euler(0, 0, 180), transform);
|
||||||
|
defaultBeam.GetComponent<LaserBeam>().Damages = _manager.BeamDamages;
|
||||||
|
|
||||||
if (laserOnX)
|
if (laserOnX)
|
||||||
{
|
{
|
||||||
@@ -64,25 +68,7 @@ public class PlayerWeapons : MonoBehaviour
|
|||||||
{
|
{
|
||||||
GameObject spawnedArrow = Instantiate(arrow, transform.position, Quaternion.identity);
|
GameObject spawnedArrow = Instantiate(arrow, transform.position, Quaternion.identity);
|
||||||
spawnedArrow.GetComponent<Arrow>().target = target;
|
spawnedArrow.GetComponent<Arrow>().target = target;
|
||||||
|
spawnedArrow.GetComponent<Arrow>().Damages = _manager.ArrowDamages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject GetClosestEnemy(GameObject[] enemies)
|
|
||||||
{
|
|
||||||
GameObject bestTarget = null;
|
|
||||||
float closestDistanceSqr = Mathf.Infinity;
|
|
||||||
Vector3 currentPosition = transform.position;
|
|
||||||
foreach (GameObject potentialTarget in enemies)
|
|
||||||
{
|
|
||||||
Vector3 directionToTarget = potentialTarget.transform.position - currentPosition;
|
|
||||||
float dSqrToTarget = directionToTarget.sqrMagnitude;
|
|
||||||
if (dSqrToTarget < closestDistanceSqr)
|
|
||||||
{
|
|
||||||
closestDistanceSqr = dSqrToTarget;
|
|
||||||
bestTarget = potentialTarget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bestTarget;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ public class Sword : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public int Damages = 25;
|
public int Damages = 25;
|
||||||
|
|
||||||
|
private PlayerManager _manager;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_manager = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerManager>();
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
Damages = _manager.SwordsDamages;
|
||||||
RotateSword();
|
RotateSword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user