Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Frost-Games · Mar 09, 2019 at 10:57 PM · invalid

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);
         }
 
 
 }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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
         }
     }*/
 
   
 }
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Frost-Games · Mar 09, 2019 at 11:05 PM 0
Share

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? :(

avatar image Frost-Games · Mar 10, 2019 at 12:02 AM 0
Share

Fixed the Layer but now the GotoState... im working on it if someone could place me in the right direction please

avatar image Frost-Games · Mar 10, 2019 at 12:28 AM 0
Share

I did it!!! Yes!!!!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

165 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I upgraded my hard drive to an SSD and now I can't use unity. It says my machine license is invalid and the sign in button doesn't work. Is there a fix? 2 Answers

i have a problem with invalid credentials,invalid credentials 1 Answer

Invalid AABB result 1 Answer

Invalid executables - the executable does not contain bitcode 1 Answer

Invalid token 'in' class, struct, or interface member declaration Problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges