Ok here’s a script called RayShootC and AiDamageC script when I press ‘F’ it should do 10 damage to the game object that has the AiDamageScript on it. ? But, the only thing working is the AudioShoot sound? Disregard the animations i don’t have any yet. I’ve been following a youtube video series from the user NarutoIsGreat1234 on how to make a fps shooter/shoot gun with C# you can even download them directly from his site in description. I type the scripts i needed with the video and then couldn’t find my error so I downloaded the script on site and the same thing is happening? No damage to my alien enemy or create my lights or particle muzzle flash.
using UnityEngine;
using System.Collections;
public class RayShootC : MonoBehaviour {
public int Clip = 80;
public int BulletsPreClip = 60;
public int BulletsLeft = 0;
public float Damage = 10;
public AudioClip ReloadSound;
public AudioClip ShootSound;
public float Range = 1000;
public ParticleEmitter muzzleFlash;
public ParticleEmitter hitParticles;
public float ReloadTime = 3.3f;
public float ShootTimer = 0;
public float ShootCooler = 0.9f;
public float muzzleFlashCooler = 0.5f;
public float muzzleFlashTimer = 0;
public float KeyCooler = 1;
public float KeyTimer = 0;
public GameObject Light1;
public GameObject Light2;
public GameObject Light3;
public float Force = 1000;
public int particleSpeed = 200000;
public float spreadFactor = 3;
// Use this for initialization
void Start () {
BulletsLeft = BulletsPreClip;
hitParticles.emit = false;
muzzleFlash.emit = false;
}
// Update is called once per frame
void Update () {
if( KeyTimer > 0){
KeyTimer -= Time.deltaTime;
}
if( KeyTimer < 0){
KeyTimer= 0;
}
if( muzzleFlashTimer > 0){
muzzleFlashTimer -= Time.deltaTime;
MuzzleFlashShow();
}
if( muzzleFlashTimer < 0){
muzzleFlashTimer = 0;
}
if(ShootTimer > 0){
ShootTimer -= Time.deltaTime;
}
if( ShootTimer < 0){
ShootTimer = 0;
}
if(KeyTimer == 0){
if(Input.GetKeyDown(KeyCode.F) BulletsLeft > 0){
if( ShootTimer == 0){
PlayShootAudio();
RayShoot();
ShootTimer = ShootCooler;
KeyTimer = KeyCooler;
}
if( muzzleFlashTimer == 0 ){
muzzleFlashTimer = muzzleFlashCooler;
MuzzleFlashShow();
}
}
}
}
void MuzzleFlashShow(){
if( muzzleFlashTimer > 0){
muzzleFlash.emit = false;
Light1.active = false;
Light2.active = false;
Light3.active = false;
}
if( muzzleFlashTimer == muzzleFlashCooler){
muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360 * particleSpeed , Vector3.forward);
muzzleFlash.emit = true;
Light1.active = true;
Light2.active = true;
Light3.active = true;
}
}
void RayShoot (){
GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Shoot");
RaycastHit hit;
//Vector3 DirectionRay = transform.TransformDirection(Vector3.forward);
Vector3 direction = transform.forward;
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
Debug.DrawRay (transform.position, direction * Range, Color.yellow);
if(Physics.Raycast(transform.position, direction , out hit, Range)){
if(hit.rigidbody){
if(hitParticles){
hitParticles.transform.position = hit.point;
hitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal);
hitParticles.Emit();
hit.rigidbody.AddForceAtPosition(direction * Force, hit.point);
hit.collider.SendMessageUpwards("ApplyDamage", Damage , SendMessageOptions.DontRequireReceiver);
}
}
}
BulletsLeft--;
if( BulletsLeft < 0){
BulletsLeft = 0;
}
if(BulletsLeft == 0){
Reload();
}
}
void PlayShootAudio(){
audio.PlayOneShot( ShootSound);
}
void PlayReloadAudio(){
audio.PlayOneShot( ReloadSound);
}
void Reload (){
StartCoroutine( ReloadSpeed());
}
IEnumerator ReloadSpeed(){
GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Reload");
PlayReloadAudio();
yield return new WaitForSeconds(ReloadTime);
if(Clip > 0){
BulletsLeft = BulletsPreClip;
}
}
}
using UnityEngine;
using System.Collections;
public class AiDamageC : MonoBehaviour {
public float MaxHealth = 100;
public float CurrentHealth = 0;
// Use this for initialization
void Start () {
CurrentHealth = MaxHealth;
}
// Update is called once per frame
void ApplyDamage ( float Damage) {
if( CurrentHealth < 0) {
return ;
}
CurrentHealth -= Damage;
if( CurrentHealth == 0){
Destroy(gameObject );
}
}
}

