This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
PMC_Projekt/ProjektUnity/Assets/Scripts/Weapon/BulletScript.cs
Marvin 1eeafca3f2 MOD: Enemy AI
MOD: Player Shooting
MOD: Damage Player and Enemy
2024-09-05 20:40:50 +02:00

31 lines
982 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
private Vector3 mousePos;
private Camera mainCamera;
private Rigidbody2D rb;
public float force;
public Weapon weapon;
// Start is called before the first frame update
void Start()
{
mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
rb = GetComponent<Rigidbody2D>();
mousePos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
Vector3 direction = mousePos - transform.position;
Vector3 rotation = transform.position - mousePos;
rb.velocity = new Vector2(direction.x, direction.y).normalized * force;
float rot = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, rot + 90);
}
private void OnTriggerEnter2D(Collider2D other) {
Destroy(this.gameObject);
}
}