- Home /
trying make a working raycast damage and death
made a gun script with animation, muzzle flash, and sound now trying add raycats damage and death, this what I got so far the top is the gun script, and bottom is the death and animation script
ps the creature ur shooting is a evil doll
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rifle : MonoBehaviour
{
public bool isFiring = false;
public GameObject muzzleFlash;
public AudioSource gunshot;
public GameObject m1;
public float damage = 10f;
public float range = 100f;
float firerate = 0.1f;
float waitfire;
public Camera fpsCam;
void Update()
{
if (Input.GetMouseButton(0))
{
if (isFiring == false)
{
StartCoroutine(FirethePistol());
}
}
}
IEnumerator FirethePistol()
{
isFiring = true;
m1.GetComponent<Animator>().Play("shotgun");
gunshot.Play();
muzzleFlash.SetActive(true);
yield return new WaitForSeconds(0.05f);
muzzleFlash.SetActive(false);
yield return new WaitForSeconds(0.2f);
m1.GetComponent<Animator>().Play("none");
isFiring = false;
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 50f;
public bool dolldying = false;
public float doll;
public void TakeDamage (float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die ()
{
doll.GetComponent<Animator>().Play("deaddoll");
dolldying.Play();
yield return new WaitForSeconds(0.05f);
Destroy(gameObject);
}
}
What are you doing in the target class, why is doll a float when you want to get it's component and why is dolldying a bool, if so why are you playing a bool?
cause there are multiple dolls of different type, dollydying is the animation of the dolls death
but you have defined doll as a float and dolldying is defined as a bool? Can you explain in detail what exactly you are ai$$anonymous$$g to achieve and what exactly is the problem?...im sorry but this is really confusing
Your answer
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
How can I animate a death sequence for the FPS controller? 1 Answer
Death animation issues. 1 Answer
Spicked Trap Hole 1 Answer
Rotation after death animation problem. 2 Answers