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().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().velocity = bulletDirection * bulletVelocity; bullet.GetComponent().damage = Damage; } } }