This is my enemy I'm cloning (instantiating). I have an error and I have set up everything correct I think.
Error:
Animator has not been initialized. UnityEngine.Animator:SetFloat(String, Single) enemyscript:playerhit() (at Assets/enemies/enemyscript.js:14)
How do I initialise the animator in every clone.
#pragma strict
var enemysmall : GameObject;
var speed : float = 1.0;
var anim : Animator;
function Start() {
this.transform.position.x = 8.325;
this.transform.position.y = -1.2;
anim = GetComponent(Animator);
anim.SetFloat("enemy1sta",0);
}
function playerhit() {
anim.SetFloat("enemy1sta",1);
}
function Update() {
this.transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
this.rigidbody2D.velocity = Vector2(-5, 0);
}
This is my on my player to spawn them from a prefab
var enemy1 : Transform;
function Start () {
///enemy1
while (true) {
yield WaitForSeconds (Random.Range(3, 5));
var enemy1Clone : Transform = Instantiate(enemy1, transform.position, transform.rotation);
enemy1Clone.GetComponent("enemyscript");
enemy1Clone.GetComponent(Animator);
}
}
And I'm using a simple
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.CompareTag("enemy") && jumped==true){
other.playerhit(); < ----- i have it so this calls the enemy function.
//Destroy(coll.gameObject);
jumpup();
jumped = true;
combo += 1;
GUIcombo.text = "COMBO: " + combo;
}
}
can someone help me with this bug its really getting me down on my first game dev