This commit is contained in:
2025-05-13 05:19:58 +03:00
parent 853edaf0b4
commit 472b2aee18
1034 changed files with 41844 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
using UnityEngine;
using System.Collections;
public class Pistol : PickableItem {
public AudioSource audioOutput;
public RandomSoundPlayer shootSound;
public AudioClip reloadSound;
public Transform shootTransform;
public Animator flash;
private bool flashVisible;
public float shotMaxDistance = 150;
public float singleShotPeriod = 0.5f;
private float _lastShotTime;
public LayerMask shootMask;
public float hitForce = 1000;
public float hitPoints = 15;
public override void OnBeginUse() {
base.OnBeginUse();
if (Time.time - _lastShotTime >= singleShotPeriod) {
Shoot();
_lastShotTime = Time.time;
}
}
// Use this for initialization
protected override void Start () {
base.Start();
// flash.SetActive(false);
}
// Update is called once per frame
void Update () {
}
public void Shoot() {
if (shootSound != null) {
shootSound.Play(true);
}
if (flash != null) {
flash.SetTrigger("Shot");
}
Vector3 right = transform.localToWorldMatrix.MultiplyVector(Vector3.right).normalized;
var hit = Physics2D.Raycast(shootTransform.position, right, shotMaxDistance, shootMask);
if (hit != null) {
//apply force
if (hit.rigidbody != null) {
Debug.Log("Add shoot force to object " + hit.transform.name);
hit.rigidbody.AddForceAtPosition(right * hitForce, hit.point);
}
//apply hit points
if (hit.transform != null) {
var health = hit.transform.gameObject.GetComponent<Health>();
if (health != null) {
health.ApplyDamage(hitPoints);
}
}
}
flashVisible = true;
}
void OnDrawGizmos() {
// if (equipped) {
if (shootTransform != null) {
Vector3 right = transform.localToWorldMatrix.MultiplyVector(Vector3.right).normalized;
Gizmos.DrawLine(shootTransform.position, shootTransform.position + right * shotMaxDistance);
}
// }
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b8315e5075683f248ab0290722f21f6c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName: