Код: Выделить всё
using UnityEngine;
using System.Collections;
public class Ammo : MonoBehaviour {
public float damage;
public float spread;
public float recoil;
public float weight;
public int clip_rounds;
public int ammo;
public Transform sparks;
public float fire_rate;
public shells shell = shells.AP_SHELL;
public enum shells {HEAT, AP_SHELL}
private int mag;
private float fire_delay = 0.0f;
public void FireA() {
RaycastHit hit;
if (Physics.Raycast (transform.position, transform.forward, out hit, Mathf.Infinity)) {
if(hit.transform.gameObject.tag=="Player"){
hit.transform.SendMessage("M_Damage", damage);
sparks.position = hit.point;
}
}
mag--;
}
// Update is called once per frame
void Update () {
switch (shell) {
case shells.AP_SHELL:
if(Input.GetButton("Fire1") && Time.time > fire_delay){
fire_delay = Time.deltaTime + fire_rate;
FireA();
}
break;
case shells.HEAT:
if(Input.GetButtonUp("Fire1") && Time.time > fire_delay) {
fire_delay = Time.deltaTime + fire_rate;
FireA();
}
break;
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/246 ... raycasthit