MOD: Enemy AI
MOD: Player Shooting MOD: Damage Player and Enemy
This commit is contained in:
30
ProjektUnity/Assets/Scripts/Weapon/BulletScript.cs
Normal file
30
ProjektUnity/Assets/Scripts/Weapon/BulletScript.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
11
ProjektUnity/Assets/Scripts/Weapon/BulletScript.cs.meta
Normal file
11
ProjektUnity/Assets/Scripts/Weapon/BulletScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 622784c880831334db51422cb3845e4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user