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 UnityCSharpNoob · Jul 29, 2016 at 12:52 PM · animationplayeraispawnbreak

My animations break when I spawn enemy

I am new to coding so bare with me.

I have a spider queen boss that spawns spiderlings when she reaches certain point in her health.

How ever when they spawn they somehow break the attack animations I have for my player. Please help me!

The code for player attack:

 using UnityEngine;
 using System.Collections;
 
 public class Sword : MonoBehaviour {
 
     static Animator anim;
 
     public GameObject hitbox;
 
    
 
     public int Sworddamage = 25;
 
     public float sec = 0.5f;
 
 
     HandS handS;
 
     public float  AttackCD;
     public float delayBetweenAttacks = 1.5f;
     public float stamDrain = 50;
     public int SwingReQ;
 
     
 
     public AudioSource WeaponSource;
     public AudioClip WeaponSound;
 
     void Start () {
 
 
         anim = GetComponentInParent<Animator>();
 
         WeaponSource = GetComponent<AudioSource>();
 
         handS = GetComponentInParent<HandS>();
        
         
      
     
     }
     
     // Update is called once per frame
     void Update () {
 
      
         attack();
         
        
 
         block();
         
  }
 
     public void attack()
     {
         
  
 
             if (Input.GetButtonDown("Fire1") && Time.time > AttackCD && handS.currentStam >= SwingReQ)
         {   
 
             AttackCD = Time.time + delayBetweenAttacks;
 
             anim.SetBool("IsAttacking", true);
   
             hitbox.SetActive(true);
 
             StartCoroutine(LateCall());
 
             handS.LessStamina(30);
 
             WeaponSource.PlayOneShot(WeaponSound);
 
             Debug.Log("hit");
 
 
         }
 
         else
         {
             anim.SetBool("IsAttacking", false);
             
         }  
 
    }
 
     public void block()
     {
         if (Input.GetButtonDown("Fire2"))
         {
             anim.SetBool("IsBlocking", true);
         }
         else
         {
             anim.SetBool("IsBlocking", false);
         }
     }
 
     IEnumerator LateCall()
     {
         yield return new WaitForSeconds(sec);
         hitbox.SetActive(false);
     }
 
 
    
 }
 






The code for the queen:

 using UnityEngine;
 using System.Collections;
 
 public class SpiderQueen: MonoBehaviour {
 
     private NavMeshAgent myAgent;
     private Animator myAnimator;
     
 
     EnemyHealth eh;
 
     public Transform target;
 
     public GameObject Spiderling;
 
     public bool chaseTarget = true;
     public float stopingDistance;
     public float delayBetweenAttacks = 1.5f;
     private float attackCD;
 
     public float SpawnSpiderling = 50;
     public int AmountSpiderling = 0;
 
 
 
     private float distanceFromTarget;
 
     // Use this for initialization
     void Start () {
 
         myAgent = GetComponent<NavMeshAgent>();
         myAnimator = GetComponent<Animator>();
         myAgent.stoppingDistance = stopingDistance;
         attackCD = Time.time;
 
         eh = GetComponentInChildren<EnemyHealth>();
     
     }
     
     // Update is called once per frame
     void Update () {
 
 
 
         
 
 
     }
 
   
 
    public void ChaseTarget()
     {
         distanceFromTarget = Vector3.Distance(target.position, transform.position);
 
         if (distanceFromTarget >= stopingDistance * 1 && distanceFromTarget <= stopingDistance * 1.1)
         {
             Attack();
         }
 
         else if(distanceFromTarget >= stopingDistance)
         {
             chaseTarget = true;
         }
         else
         {
             AttackL();
             chaseTarget = false;
             
         }
         if (chaseTarget)
         {
             myAgent.SetDestination(target.position);
             myAnimator.SetBool("IsWalking", true);
         }
         else
         {
             myAnimator.SetBool("IsWalking", false);
         }
         if(eh.currentHealth <= SpawnSpiderling)
         {
             while(AmountSpiderling < 5)
             {
                Instantiate(Spiderling, transform.position, transform.rotation);
                 AmountSpiderling++;
             }
             
         }
     }
 
     void Attack()
     {
         if(Time.time > attackCD)
         {
             Debug.Log("Attack");
             myAnimator.SetTrigger("Attack");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 
     void AttackL()
     {
         if(Time.time > attackCD)
         {
             myAnimator.SetTrigger("AttackL");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 
     void AttackR()
     {
         if(Time.time > attackCD)
         {
             myAnimator.SetTrigger("AttackR");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 
     void StartAttack()
     {
         transform.RotateAround(target.position, Vector3.up, 20 * Time.deltaTime);
     }
 }

The code for the spiderling:

 using UnityEngine;
 using System.Collections;
 
 public class Spiderling : MonoBehaviour {
 
     private NavMeshAgent myAgent;
     private Animator myAnimator;
 
 
 
 
    public Transform target;
 
     
 
     public bool chaseTarget = true;
     public float stopingDistance;
     public float delayBetweenAttacks = 1.5f;
     private float attackCD;
 
     private float distanceFromTarget;
 
     void Awake()
     {
         target = GameObject.FindWithTag("Player").transform;
         myAgent = GetComponent<NavMeshAgent>();
         myAnimator = GetComponent<Animator>();
         myAgent.stoppingDistance = stopingDistance;
         attackCD = Time.time;
 
           
     }// Use this for initialization
 
     void Start()
     {
         
 
        
 
        
       
         
 
     }
 
     void Update()
     {
        Chaseplayer(); 
     }
   
 
 
     private void Chaseplayer()
     {
         distanceFromTarget = Vector3.Distance(target.position, transform.position);
 
 
          if (distanceFromTarget >= stopingDistance)
         {
             chaseTarget = true;
         }
         else if(distanceFromTarget <= stopingDistance)
         {
             Attack();
             chaseTarget = false;
 
         }
         if (chaseTarget)
         {
             myAgent.SetDestination(target.position);
             myAnimator.SetBool("IsWalking", true);
         }
         else
         {
             myAnimator.SetBool("IsWalking", false);
         }
       
     }
 
     void Attack()
     {
         if (Time.time > attackCD)
         {
             Debug.Log("Attack");
             myAnimator.SetTrigger("Attack");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 
     void AttackL()
     {
         if (Time.time > attackCD)
         {
             myAnimator.SetTrigger("AttackL");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 
     void AttackR()
     {
         if (Time.time > attackCD)
         {
             myAnimator.SetTrigger("AttackR");
             attackCD = Time.time + delayBetweenAttacks;
         }
     }
 }
 


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 UnityCSharpNoob · Jul 29, 2016 at 01:03 PM

Could it have something to do with my weapon switching code?

 using UnityEngine;
 using System.Collections;
 
 public class SwitchWeapons : MonoBehaviour
 {
     static Animator anime;
     public GameObject Sword;
     public GameObject Axe;
     public GameObject Magic;
     public GameObject Model2;
     
 
     // Use this for initialization
     void Start()
     {
         Model2.SetActive(false);
         anime = gameObject.GetComponent<Animator>();
 
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         if (Input.GetButtonDown("1"))
         {
             Model2.SetActive(false);
             Sword.SetActive(true);
 
             Axe.SetActive(false);
             Magic.SetActive(false);
             anime.SetBool("IsBlocking", true);
 
             
 
 
         }
         if (Input.GetButtonDown("2"))
         { 
             Axe.SetActive(true);
             
             Sword.SetActive(false);
             Magic.SetActive(false);
 
             Model2.SetActive(false);
 
 
         }
         if (Input.GetButtonDown("3"))
         {
             Model2.SetActive(true);
             Magic.SetActive(true);
 
             Sword.SetActive(false);
             Axe.SetActive(false);
             
         }
 
     }
 }
Comment
Add comment · 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

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

139 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

Related Questions

Enemy AI script for 2D platformer 1 Answer

How to create transitions in the animator without creating a disaster? (Layers?) 0 Answers

performing animation on another player 0 Answers

How do I add animation to my script? 1 Answer

How do I fix my animations after duplicating my character? 0 Answers


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