Startpunkten

This commit is contained in:
2026-04-20 13:09:07 +02:00
commit 1e9f31f003
177 changed files with 77970 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using UnityEngine;
public class ShotAway : MonoBehaviour {
[SerializeField] private float ShotSpeed = 15f;
Vector3 direction;
GameController gameController;
void Start() {
gameController = FindFirstObjectByType<GameController>();
}
public void SetDirection(Vector3 dir) {
direction = dir.normalized;
// Beräkna vinkel i grader
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
// Sätt rotation på projektilen
transform.rotation = Quaternion.Euler(0, 0, angle);
}
void Update() {
transform.position += direction * ShotSpeed * Time.deltaTime;
}
void OnTriggerEnter2D(Collider2D collision) {
if (collision.CompareTag("Enemy")) {
Destroy(collision.gameObject); // Ta bort fienden
Destroy(gameObject); // Ta bort projektilen
gameController.KilledAnemy();
}
}
}