-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapon.cs
39 lines (29 loc) · 1 KB
/
weapon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weapon : MonoBehaviour
{
public Transform firepoint;
public GameObject bullet;
public float force = 20f;
public Vector2 look;
public float angle;
// Update is called once per frame
void Update()
{
look = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
angle = Mathf.Atan2(look.y, look.x) * Mathf.Rad2Deg;
firepoint.rotation = Quaternion.Euler(0f, 0f, angle );
if (Input.GetButtonDown("Fire1"))
{
Shoot();
FindObjectOfType<audiomanager>().Play("PlayerShoot");
}
}
void Shoot()
{
GameObject B = Instantiate(bullet, firepoint.position, firepoint.rotation);
Rigidbody2D rb = B.GetComponent<Rigidbody2D>();
rb.AddForce(firepoint.up * force, ForceMode2D.Impulse);
}
}