48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Assets.Scripts;
|
|
using UnityEngine;
|
|
|
|
public class CapsulePlacer : MonoBehaviour
|
|
{
|
|
public Transform objectA;
|
|
public Transform objectB;
|
|
private bool laserEnabled;
|
|
private void Awake()
|
|
{
|
|
if(objectA == null || objectB == null)
|
|
{
|
|
laserEnabled = false;
|
|
Debug.LogError("Les boules du laser ne sont pas définis.");
|
|
}
|
|
|
|
laserEnabled = DataBearer.Instance.Rules.Lasers;
|
|
if (!laserEnabled)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
Vector2 positionA = objectA.position;
|
|
Vector2 positionB = objectB.position;
|
|
|
|
// Calcul de la distance et mise à jour de l'échelle
|
|
float distance = Vector2.Distance(positionA, positionB);
|
|
Vector3 localScale = transform.localScale;
|
|
localScale.y = distance / 2f;
|
|
transform.localScale = localScale;
|
|
|
|
// Mise à jour de la position
|
|
transform.position = (positionA + positionB) / 2f;
|
|
|
|
// Calcul de la direction et de l'angle
|
|
Vector2 direction = positionB - positionA;
|
|
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + 90f;
|
|
|
|
// Mise à jour de la rotation
|
|
transform.rotation = Quaternion.Euler(0f, 0f, angle);
|
|
}
|
|
}
|