Invalid Layer
I have a script (the first one below) that if I press X the player animates and the sword as well if its equipped. The player animates correctly when i press X but the sword animation dont show at all.
The problem as i understand it that cant find it since its on -1 and cant play the animation but i never had a -1 layer and never had anything there as far as i understand. Below is the problem Unity points to with the Invalid Layer -1 problem. I have to clue on what to do to to fix it some please help me. And talk to me like im a noob-ish
public void PlayAnimation(AnimationClip clip) {
//anim.SetInteger("State", 1);
anim.Play(clip.name);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private Weapon weaponEquipped;
private Attack attack;
private Animator anim;
public float fireRate;
private float nextAttack;
void Start()
{
anim = GetComponent<Animator>();
attack = GetComponentInChildren<Attack>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.X) && Time.time > nextAttack && weaponEquipped !=null)
{
anim.SetTrigger("Blade_Attack");
attack.PlayAnimation(weaponEquipped.animation);
nextAttack = Time.time + fireRate;
}
}
public void AddWeapon(Weapon weapon)
{
weaponEquipped = weapon;
GetComponentInChildren<Attack>().SetWeapon(weaponEquipped.damage);
}
}
Answer by Frost-Games · Mar 09, 2019 at 10:59 PM
And here is the attack script attached to the game object with the animation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour {
private Animator anim;
private int damage;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
public void PlayAnimation(AnimationClip clip)
{
//anim.SetInteger("State", 1);
anim.Play(clip.name);
}
public void SetWeapon(int damageValue)
{
damage = damageValue;
}
public int GetDamage()
{
return damage;
}
/*private void OnTriggerEnter2D(Collider2D other)
{
Enemy enemy = other.GetComponent<Enemy>();
if(enemy != null)
{
enemy.TakeDamage(damage);//despues de damage + FindObjectOfType<Player>().strength si vas a usar la fuerza
}
}*/
}
Actually it shows another error,
Animator.GotoState State could not be found Unity.Engine.Animator:Play(String)
i setted up the animator but it seems not? maybe i missed something here... as well? :(
Fixed the Layer but now the GotoState... im working on it if someone could place me in the right direction please