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/Enemy 2/CornerEnemy/EnemyBulletScript.cs

33 lines
798 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBulletScript : MonoBehaviour
{
public GameObject player;
public Rigidbody2D rb;
public float force;
public float rotation;
public GameObject[] bullets;
void Start()
{
rb = GetComponent<Rigidbody2D>();
player = GameObject.FindGameObjectWithTag("Player");
Vector3 direction = player.transform.position - transform.position;
rb.velocity = new Vector2(direction.x, direction.y).normalized * force;
float rot = Mathf.Atan2(-direction.y, -direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0,0, rot + rotation);
}
// Update is called once per frame
void Update()
{
}
}