Question by
zafranalon · Feb 14, 2021 at 07:58 PM ·
c#animationenemygun script
hi, i am making a retro game and i have an enemy, and i also have a shoot animation, but whenever i click the mouse the enemy dies, i only want it to be on the animation, how do i do it?
using UnityEngine;
using System.Collections;
public class shoot : MonoBehaviour
{
public int ammo;
public Animator anim;
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
public AudioSource shootSnd;
public bool canShoot;
// Start is called before the first frame update
void Start()
{
ammo = 10;
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
anim.SetBool("shoot", true);
}
else
{
anim.SetBool("shoot", false);
}
}
public void GunShoot()
{
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);
}
}
}
}
Comment