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
1
Question by tiyyargee · Apr 24, 2016 at 08:07 PM · c#animatorclickattackcombo

any triple mouse click c# script?

hey guys i have a single and double mouse click working good but i need to add triple mouse click to perform a combo attack. here is my script, and please if anyone can help with another problem that is when i double click the mouse the animator plays the single click animation and than it plays double click animation , i dont want that , i want when i double click to directly perform the second attack without passing by the first attack N.B: i made lot of research but i couldnt find any help before i asked here sorry for my english using UnityEngine; using System.Collections;

public class playercombat : MonoBehaviour { private float lastTapTime = 0; float tapSpeed = .5f;

 public static Transform opponent;
 public float inrange;
 
 Animator anim;




 // Use this for initialization
 void Start ()
 {
     anim = GetComponent<Animator> ();

 }
 
 // Update is called once per frame
 void Update () 
 {
     /*if (Input.GetMouseButtonDown(0)&& WieldWeapon.equiped == true)
     {
         if ( anim.GetInteger("Attack")==0)
         anim.SetInteger("Attack", Random.Range(1,4));
         Invoke("stoppress", 0.02f);

     }
   */



     if (Input.GetMouseButtonDown (0) && WieldWeapon.equiped == true) 
     {

         if ((Time.time - lastTapTime) > tapSpeed)
         {
             anim.SetTrigger("slash");

         }
         else
         {
             anim.SetTrigger("slash2");
         }
         lastTapTime = Time.time;
     }

    
 }

 void stoppress()
 {
     anim.SetInteger("Attack",0);
 }



}

Comment
Add comment · Show 2
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 Le-Pampelmuse · Apr 24, 2016 at 08:36 PM 2
Share

Hi.

  • Format your question properly please.
    Start sentences with capital letters, make line breaks so your text isn't one long strip of words. Use the 101010 button for code.

  • Don't ask for code. Learning and trying is the only way you can improve your work.

  • ...I made lot of research but i couldnt find any help
    How about this one: http://answers.unity3d.com/questions/283218/how-do-you-script-combo-attacks.html

avatar image AK-64 Le-Pampelmuse · Apr 25, 2016 at 04:15 AM 0
Share

$$anonymous$$y bad, somehow I got two answers submitted. Not sure how

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AK-64 · Apr 24, 2016 at 11:03 PM

I've rewritten your code with a solution, please try to understand how it works. Make sure to mark this answer if it works for you. You're welcome! :)

 using UnityEngine;
 using System.Collections;
 
 public class playercombat : MonoBehaviour {
     public static Transform opponent;
     public float tapSpeed = 0.2f;
     private float lastTapTime = -10f;
     private int clickCount = 0;
     
     // Use this for initialization
     void Start ()
     {
      anim = GetComponent<Animator> ();
     }
     
     // Update is called once per frame
     void Update () 
     {
         /*if (Input.GetMouseButtonDown(0)&& WieldWeapon.equiped == true)
         {
         if ( anim.GetInteger("Attack")==0)
         anim.SetInteger("Attack", Random.Range(1,4));
         Invoke("stoppress", 0.02f);
         }
         */
         
         if (Input.GetMouseButtonDown (0)) 
         {
             lastTapTime = Time.time;
             
             if ((Time.time - lastTapTime) < tapSpeed)
             {
                 clickCount += 1;
                 
                 if(clickCount >= 3)
                 {
                     anim.SetTrigger("slash3");
                     clickCount = 0;
                 }
             }
         }
         
         if ((Time.time - lastTapTime) > tapSpeed)
         {
             if (clickCount == 2)
             {
                 anim.SetTrigger("slash");
                 clickCount = 0;
             }
             else if (clickCount == 1)
             {
                 anim.SetTrigger("slash2");
                 clickCount = 0;
             }
             
             clickCount = 0;
         }
     }
     
     void stoppress()
     {
         anim.SetInteger("Attack",0);
     }
 }
Comment
Add comment · Show 5 · 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 tiyyargee · Apr 25, 2016 at 07:09 PM 0
Share

it works man ,thanks a lot , but it needs some work to achieve my desire, thanks for your time brother

avatar image AK-64 tiyyargee · Apr 27, 2016 at 05:21 PM 0
Share

$$anonymous$$ake sure you mark this answer as correct so that the question gets marked as solved ;)

avatar image ItTookMe2MonthsToCreateAnAccountHereSuccessfully AK-64 · Apr 30, 2016 at 01:50 PM 0
Share

Why would the OP mark an answer as correct if it doesn't achieve what he asked for?

$$anonymous$$ake sure your answers helpful and pertaining to the question's situation and you will get positive votes.

Begging for votes is lame.

Show more comments
avatar image Xarbrough · Apr 25, 2016 at 08:56 PM 0
Share

I know this is a beginner discussion, but I believe it's never to early to start thinking about separating things into conceptual bits and structure code so that it doesn't repeat itself. If you achieve this, the code becomes much simpler and all of a sudden these problems don't appear as daunting as they may seem in the beginning. :)

avatar image
0

Answer by Xarbrough · Apr 25, 2016 at 08:49 PM

I would try to look at scripting from a problem-point-of-view. Try to break apart what you need to do to achieve the result. For example: I need 3 different actions for click, double and triple click. So what's the difference between clicks? Well, they all happen within a short time. So I need to define a time for which I count the number of clicks. That also means I can't call my first action on the first click, but I have to actually wait that short period of time to see if any other clicks will follow after the first. Only when e.g. half a second is over, can I look back and see how many clicks have happened and then decide what to do with it.

Here's my code, if you don't know about events and coroutines yet, you can build the same system only using the Update loop and method calls. Just think of the IEnumerator bit as a timer that counts down and then resets the click count. You can replace the events with simple method calls, it's just good practice to separate things like user input and things that happen.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Events;
 
 public class MouseClick : MonoBehaviour
 {
     /// <summary>
     /// The time for which to wait for consecutive clicks after the first click.
     /// </summary>
     public float clickTimeout = 0.3f;
 
     public UnityEvent OnClick;
     public UnityEvent OnDoubleClick;
     public UnityEvent OnTripleClick;
 
     int clickCount;
     bool isFirstClick = true;
 
     void Start()
     {
         OnClick.AddListener(() => Debug.Log("Click"));
         OnDoubleClick.AddListener(() => Debug.Log("Double Click"));
         OnTripleClick.AddListener(() => Debug.Log("Triple Click"));
     }
 
     void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             clickCount++;
             if (isFirstClick)
             {
                 isFirstClick = false;
                 StartCoroutine(Timer());
             }
         }
     }
 
     IEnumerator Timer()
     {
         yield return new WaitForSeconds(clickTimeout);
         EvaluateClickCount(clickCount);
         clickCount = 0;
         isFirstClick = true;
     }
 
     void EvaluateClickCount(int clickCount)
     {
         if (clickCount == 1)
             if (OnClick != null) OnClick.Invoke();
 
         if (clickCount == 2)
             if (OnDoubleClick != null) OnDoubleClick.Invoke();
 
         if (clickCount >= 3)
             if (OnTripleClick != null) OnTripleClick.Invoke();
     }
 } 

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

6 People are following this question.

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

Related Questions

Range Attack + Animation Script 0 Answers

MobController 1 Answer

Take damage only when attack animation is done? 1 Answer

How to ignore a value while animating 0 Answers

I can not modify localscale while I'm playing because of the Animator. 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