31 lines
942 B
C#
31 lines
942 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
//Ben Keller
|
|
public class BulletScript : MonoBehaviour
|
|
{
|
|
private Vector3 mousePos;
|
|
private Camera mainCamera;
|
|
private Rigidbody2D rb;
|
|
public float force;
|
|
|
|
public Weapon weapon;
|
|
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);
|
|
}
|
|
}
|