I’m currently working at a small fps. I made a small script for a weapon that user raycasts to shoot. When those raycasts hit a certain point they create some impact particles. What i want is when i hit an enemy, I need to play some different particles (for ex. blood) but when i hit the wall play other particles.
Here’s my gun script:
void Start()
{
anim = GetComponent<Animation>();
anim.Play("recoilrifle");
audioData = GetComponent<AudioSource>();
Overheat = 0f;
ammo = 40f;
}
// Update is called once per frame
void Update()
{
ammoCount.text = ammo.ToString("00");
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
}
public void OverheatWeapon()
{
heat.StopGun();
}
public void ResetFloat()
{
Overheat = 0f;
ammo = 40f;
}
void FixedUpdate()
{
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
anim.Play();
anim.Play();
}
}
void Shoot()
{
muzzleflash.Play();
Overheat += 1f;
ammo -= 1f;
anim.Play("recoilrifle");
audioData.Play();
RaycastHit hit;
if (Physics.Raycast(fpscamera.transform.position, fpscamera.transform.forward, out hit, range))
{
UnityEngine.Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGO, 2f);
}
if (Overheat > 40f)
{
OverheatWeapon();
}
}
}
Also my target script:
void Start()
{
animator = GetComponentInChildren<Animator>();
animator.SetBool("Die", false);
Active = true;
animator = GetComponentInChildren<Animator>();
}
public void TakeDamage(float amount)
{
health -= amount;
animator.SetBool("Hit", true);
Invoke("HitFalse", delay2);
psh.Play();
if (health <= 0f)
{
animator.SetBool("Aware", false);
animator.SetBool("Atack", false);
ai.GetComponent<EnemyAiTutorial>().enabled = false;
animator.SetBool("Die", true);
ps.Play();
Invoke("Follow", delay1);
Invoke("Die", delay);
Invoke("ActivePortal", delay1);
}
}
private void HitFalse()
{
animator.SetBool("Hit", false);
}
void ActivePortal()
{
activatePortal.Increase();
}
void Follow()
{
Active = false;
}
void Die()
{
Destroy(gameObject);
}
private void Update()
{
if (health <= 0f)
{
animator.SetBool("Hit", false);
}
}
Thanks in advance!