- Home /
Question by
Mellevh · Mar 27, 2019 at 04:40 PM ·
animationtriggerdelayanimation controller
making an arrowgrab animation play when attackdelay = 0.
helloi am a beginner of unity and I have been trying for an hour to make my arrowgrab animation play whenever timeBtwAttack = 0 and now i am totally lost of ideas and i need some help.
if anybody knows this hes a hero.`using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class bow_attack : MonoBehaviour { public float arrowgrabTime; private int cangrab;
private float timeBtwFire;
public float startTimeBtwFire;
public Image timeBtwBarr;
public Canvas timeBarr;
public Transform firePoint;
public KeyCode fire;
public Animator goblin;
public GameObject arrowPrefab;
public GameObject arrow;
void Start()
{
goblin.GetComponent<Animator>();
timeBtwFire = startTimeBtwFire;
goblin.SetBool("always true", true);
}
void Update()
{
timeBtwFire -= Time.deltaTime;
timeBtwBarr.fillAmount = timeBtwFire / startTimeBtwFire;
if (timeBtwFire <= 0)
{
arrow.gameObject.SetActive(true);
timeBarr.gameObject.SetActive(false);
}
else
{
timeBarr.gameObject.SetActive(true);
arrow.gameObject.SetActive(false);
}
if (timeBtwFire <= 0 && Input.GetKeyDown(fire))
{
shoot();
timeBtwFire = startTimeBtwFire;
goblin.SetTrigger("shoot");
cangrab = 1;
} else goblin.SetBool("shooting", false);
if(cangrab == 1)
{
wait();
}
}
void shoot()
{
Instantiate(arrowPrefab, firePoint.position, firePoint.rotation);
}
private IEnumerator wait()
{
yield return new WaitForSeconds(startTimeBtwFire);
goblin.SetBool("grabbing 0", true);
yield return new WaitForSeconds(arrowgrabTime);
goblin.SetBool("grabbing 0", false);
cangrab = 0;
}
} `
Comment