- Home /
Question by
spacegamer179 · Feb 08 at 09:46 AM ·
animationanimatorcamera movementanimation controller
Animation that includes camera keyframes make the camera unusable in game
It s a gun reload animation and it s stopping all the other animations and make the fps camera unusable. I am using 2 animators, one for idle,shoot and one for reload that I put in the camera, and the camera is the parent of the gun.
If I use an override then the reload animation dosen t work.
This is the script for the gun.
If I need to give more information I will give more.
using UnityEngine;
using TMPro;
public class shoot : MonoBehaviour
{
//Gun stats
public int damage;
public float timeBetweenShooting, spread, range, reloadTime, timeBetweenShots;
public int magazineSize, bulletsPerTap;
public bool allowButtonHold;
int bulletsLeft, bulletsShot;
//bools
bool shooting, readyToShoot, reloading;
//Reference
public Camera fpsCam;
public Transform attackPoint;
public RaycastHit rayHit;
public LayerMask whatIsEnemy;
//Graphics
public GameObject muzzleFlash, bulletHoleGraphic;
public CameraShake camShake;
public float camShakeMagnitude, camShakeDuration;
public TextMeshProUGUI text;
public Animator anim;
public Animator anim2;
public AudioClip Shoott;
public AudioClip reload;
public AudioSource aud;
public GameObject gun;
private void Awake()
{
bulletsLeft = magazineSize;
readyToShoot = true;
}
private void LateUpdate()
{
MyInput();
//SetText
text.SetText(bulletsLeft + " / " + magazineSize);
}
private void MyInput()
{
if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
else shooting = Input.GetKeyDown(KeyCode.Mouse0);
if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
//Shoot
if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
{
bulletsShot = bulletsPerTap;
Shoot();
anim.SetBool("shoot", true);
Invoke("Test", 0.7f);
aud.PlayOneShot(Shoott);
}
}
private void Shoot()
{
readyToShoot = false;
//Spread
float x = Random.Range(-spread, spread);
float y = Random.Range(-spread, spread);
//Calculate Direction with Spread
Vector3 direction = gun.transform.right * -1 + new Vector3(x, y, 0);
//RayCast
if (Physics.Raycast(gun.transform.position, direction, out rayHit, range, whatIsEnemy))
{
Debug.Log(rayHit.collider.name);
}
//ShakeCamera
StartCoroutine( camShake.Shake(camShakeDuration, camShakeMagnitude));
//Graphics
Instantiate(bulletHoleGraphic, rayHit.point + new Vector3(0, 0, -0.5f), Quaternion.Euler(0, 0, 0));
Instantiate(muzzleFlash, attackPoint.position, attackPoint.rotation);
bulletsLeft--;
bulletsShot--;
Invoke("ResetShot", timeBetweenShooting);
if (bulletsShot > 0 && bulletsLeft > 0)
Invoke("Shoot", timeBetweenShots);
}
private void ResetShot()
{
readyToShoot = true;
}
private void Reload()
{
anim2.SetBool("Reload", true);
aud.PlayOneShot(reload);
reloading = true;
Invoke("ReloadFinished", reloadTime);
Invoke("Test2", 6);
}
private void ReloadFinished()
{
bulletsLeft = magazineSize;
reloading = false;
}
void Test()
{
anim.SetBool("shoot", false);
}
void Test2()
{
anim2.SetBool("Reload", false);
}
}
Comment
Your answer
Follow this Question
Related Questions
How would one make a Health Bar decrease if a player is in a specific animation state? 1 Answer
Copy the state of one animator to another 0 Answers
Animations don't work with humanoid avatars 0 Answers
How to nest Animation file in an Animation Controller? 1 Answer
Precise animation control 4 Answers