Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by adrianpogi14 · Feb 14, 2021 at 04:54 PM · animationscript.attack

activate animation using another scripts

Hi guys here's the thing i want may character to do attack animation so the scenario is im using now is i have 2 scrip the 1st scrip is for the power meter bar that continuously go up and down and it will stop once mouse is click, 2nd scrip is for my character animation once click my character will do attack animation. both scrip is working well, but i want to change the scenario instead of attack animation by mouse click, what i want is may character will do the attack animation if my power meter bar hit the exact spot

here is my power meter code

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LineMove: MonoBehaviour
 {
     bool upOrDown = true; //whether we are moving up or down
     bool stopped = false;    //whether we have stopped or not
     public float upSpeed;    //our upwards movement speed
     public float downSpeed;    //our downwards movement speed
     public float maxHeight;    //the max height at which we will change direction
     public float minHeight;    //the min height at which we will change direction
     public float minWinHeight;    //the minimum height we must be at to win
     public float maxWinHeight;    //the maximum height we must be at to win
 
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Mouse0))
         {    //if the mouse is clicked
             stopped = true;    //then stop
             Stopped();
         }
         if (!stopped)
         { //if we haven't stopped
             MoveUpDown(); //move line
         }
     }
 
 
     void MoveUpDown()
     {
         if (upOrDown)
         {    //if we are moving up
             transform.Translate(Vector3.up * upSpeed);    //move up
             if (transform.position.y > maxHeight)
             {    //if we are at the max height
                 upOrDown = false;    //switch to moving down
             }
         }
         else
         {    //if we are moving down
             transform.Translate(Vector3.up * -downSpeed);    //move down
             if (transform.position.y < minHeight)
             {    //if we are at the min height
                 upOrDown = true; //switch to moving up
             }
         }
     }
 
 
     void Stopped()    //when we have stopped
     {
         if (transform.position.y > minWinHeight && transform.position.y < maxWinHeight)
         {
             Debug.Log("YOU WIN!!!");    //if line is between win min and max height we win or lose
         }
         else
         {
             Debug.Log("YOU LOSE");
         }   
     }
 }
 

and here is my attack animation

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class AnimatorXD : MonoBehaviour { private Animator anim;

 void Start()
 {
     anim = GetComponent<Animator>();
 }

void Update() { if (Input.GetKey(KeyCode.Mouse0)) { anim.SetBool("isAttack", true); } else { anim.SetBool("isAttack", false); } } }

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 Nistroy · Feb 14, 2021 at 06:06 PM

The idea is these @adrianpogi14 :

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class LineMove: MonoBehaviour
  {
       Attack attackScript;
 
      bool upOrDown = true; //whether we are moving up or down
      bool stopped = false;    //whether we have stopped or not
      public float upSpeed;    //our upwards movement speed
      public float downSpeed;    //our downwards movement speed
      public float maxHeight;    //the max height at which we will change direction
      public float minHeight;    //the min height at which we will change direction
      public float minWinHeight;    //the minimum height we must be at to win
      public float maxWinHeight;    //the maximum height we must be at to win
  
      void Start()
      {
             attackScript = GetComponent<AttackScript>();
      }
 
 
      void Update()
      {
          if (Input.GetKeyDown(KeyCode.Mouse0))
          {    //if the mouse is clicked
              stopped = true;    //then stop
              Stopped();
          }
          if (!stopped)
          { //if we haven't stopped
              MoveUpDown(); //move line
          }
      }
  
  
      void MoveUpDown()
      {
          if (upOrDown)
          {    //if we are moving up
              transform.Translate(Vector3.up * upSpeed);    //move up
              if (transform.position.y > maxHeight)
              {    //if we are at the max height
                  upOrDown = false;    //switch to moving down
              }
          }
          else
          {    //if we are moving down
              transform.Translate(Vector3.up * -downSpeed);    //move down
              if (transform.position.y < minHeight)
              {    //if we are at the min height
                  upOrDown = true; //switch to moving up
              }
          }
      }
  
  
      void Stopped()    //when we have stopped
      {
          if (transform.position.y > minWinHeight && transform.position.y < maxWinHeight)
          {
              Debug.Log("YOU WIN!!!");    //if line is between win min and max height we win or lose
              attackScript.Attack(); // Invoke Attack method
          }
          else
          {
              Debug.Log("YOU LOSE");
          }   
      }
  }



And in your Attack script

 public void Attack()
 {
        anim.SetBool("isAttack", true);
 }





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

300 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Button press for Animations 1 Answer

Animation not at correct position W/Video 0 Answers

Sliding Issue with my animation 1 Answer

My Scripts keeps giving me unexpecter char errors! 1 Answer

My animation is not playing 2 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