using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
public float damage = 21f;
public float fireRate = 1f;
public float force = 150f;
public float range = 15f;
public ParticleSystem muzzleFlash;
public Transform bulletSpawn;
public AudioClip shotSFX;
public AudioSource _audioSource;
public Camera _cam;
public float nextFire = 0f;
// Start is called before the first frame update
// se poate de pus (f) la orice cifra din cauza ca e float...
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!(!Input.GetButton("Fire1") && Time.time > nextFire))
{
nextFire = Time.time = 1f / fireRate;
Shoot();
}
}
void Shoot()
{
_audioSource.PlayOneShot(shotSFX);
//Instantiate(muzzleFlash, bulletSpawn.position, bulletSpawn.rotation);
muzzleFlash.Play();
RaycastHit hit;
if(Physics.Raycast(_cam.transform.position,_cam.transform.forward,out hit,range))
{
Debug.Log(" there's hit! " + hit.collider);
if(hit.rigidbody !=null)
{
hit.rigidbody.AddForce(-hit.normal * force);
}
}
}
}
![alt text][1]
[1]: /storage/temp/201934-снимок.png
↧