init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
27
Assets/Scripts/Weapon.cs
Normal file
27
Assets/Scripts/Weapon.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue