27 lines
996 B
C#
27 lines
996 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Weapon : MonoBehaviour
|
|
{
|
|
public float bulletVelocity;
|
|
public float fireRate;
|
|
public float Damage;
|
|
public GameObject bulletPrefab;
|
|
|
|
private float lastTimeShot;
|
|
|
|
public void shoot() {
|
|
if (Time.time > lastTimeShot + fireRate) {
|
|
GetComponentInChildren<Animator>().SetTrigger("Shoot");
|
|
lastTimeShot = Time.time;
|
|
GameObject bullet = Instantiate(bulletPrefab);
|
|
bullet.transform.rotation = gameObject.transform.rotation;
|
|
bullet.transform.position = gameObject.transform.position;
|
|
Vector2 bulletDirection = bullet.transform.right;
|
|
bullet.transform.position += new Vector3(bulletDirection.x, bulletDirection.y, 0) * 1;
|
|
bullet.GetComponent<Rigidbody2D>().velocity = bulletDirection * bulletVelocity;
|
|
bullet.GetComponent<BulletScript>().damage = Damage;
|
|
}
|
|
}
|
|
}
|