using UnityEngine;
using System.Collections;
public class FireController : MonoBehaviour {
public GameObject bulletPrototype;
Animator anim;
bool onFire = false;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate () {
if(onFire){
anim.SetTrigger("Bullet");
onFire = false;
}
}
public void animat(){
onFire = true;
}
public void Shoot(){
GameObject bulletCopy = Instantiate (bulletPrototype);
bulletCopy.transform.position = new Vector3(transform.parent.position.x+1.35f,transform.parent.position.y+0.15f,0f);
bulletCopy.GetComponent<BulletController> ().direction = new Vector3 (transform.parent.localScale.x,0,0);
}
}
Go to Window > Animator |||||
Than in the up left corner you should see Layers, Parameters |||||
Click on Parameters |||||
Than on the little “+” sign |||||
And pick Trigger |||||
Than make as many as you need and rename them on what you need |||||
||||| example… rename the trigger to Bullet |||||
I think the problem is that I had placed an animator in object that is a child of another object which already has an animator, so only the parameters used for the father’s animator are useful; I solved this problem by creating an animation from the father object.
That is the only solution that I have found.
If the error is from AssetDatabase.Refresh(): “Parameter ‘Normal’ does not exist.
UnityEditor.AssetDatabase:Refresh()”, you can put the Refresh call in a Couroutine with “yield return null;” before it, to fix the warning.