• 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 Razor1589 · Dec 22, 2017 at 11:16 AM · animations3d modelscomboattacking

How to make so when i press the left mouse button the 3D model attacks, and when i press it again it makes the next attack animation and the next total of 3 animations in a row like a combo click animations?

using UnityEngine; using System.Collections;

public class pplayer : MonoBehaviour {

 private Animator anim;
 private CharacterController PlayerController;

 public Vector3 jump;
 public float speed = 6.0f;
 public float turnSpeed = 100.0f;
 private Vector3 moveDirection = Vector3.zero;
 public float gravity = 14.0f;
 private float verticalVelocity;
 private float jumpForce = 80.0f;

 public bool isGrounded;
 Rigidbody rb;

 int noOfClicks = 0;
 float lastClickedTime = 0;
 float maxComboDelay = 1;


 void Start () 
 {
     PlayerController = GetComponent <CharacterController>();
     anim = gameObject.GetComponentInChildren<Animator>();
     jump = new Vector3 (0.0f, 2.0f, 0.0f);
 }

 void OnCollisionStay()
 {
     isGrounded = true;
 }

 void Update ()
 {
     if (Input.GetKeyDown (KeyCode.Space) && isGrounded) {
         rb.AddForce (jump * jumpForce, ForceMode.Impulse);
         isGrounded = false;
     } 
     //if (PlayerController.isGrounded) 
     //{
     //    verticalVelocity = -gravity * Time.deltaTime;
     //    if (Input.GetKeyDown (KeyCode.Space)) 
     //    {
     //        verticalVelocity = jumpForce;
     //        anim.SetBool ("Jump", true);
     //    }
     //    else 
     //    {
     //        verticalVelocity -= gravity * Time.deltaTime;
     //        anim.SetBool ("Jump", false);
         //}
     //    Vector3 moveVector = new Vector3 (0, verticalVelocity, 0);
     //    PlayerController.Move (moveVector * Time.deltaTime);
     //}

     //if (Input.GetKey (KeyCode.Space)) 
     //{
     //    anim.Play ("JUMP", -1,0f);
     //}  


     if (Input.GetMouseButtonDown (1)) 
     {
         anim.SetBool ("Skill",true);
     } else {
         anim.SetBool ("Skill", false);
     }


     if (Input.GetMouseButtonDown (0)) 
     {
         anim.SetBool ("Attack", true);
     } else {
         anim.SetBool ("Attack", false);
     }

     if (Input.GetKey ("w")) 
     {
         anim.SetInteger ("AnimPar", 1);
     }  
     else 
     {
         anim.SetInteger ("AnimPar", 0);
     }

     if (Input.GetKey ("s")) {
         anim.SetInteger ("AnimPar1", 1);
     }  
     else 
     {
         anim.SetInteger ("AnimPar1", 0);
     }

     if(PlayerController.isGrounded){
         moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
     }

     float turn = Input.GetAxis("Horizontal");
     transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
     PlayerController.Move(moveDirection * Time.deltaTime);
     moveDirection.y -= gravity * Time.deltaTime;

     if (Time.time - lastClickedTime > maxComboDelay) {
         noOfClicks = 0;
     }

 }
     
 void OnClick()
 {
     lastClickedTime = Time.time;
     noOfClicks++;
     if (noOfClicks == 1)
     {
         anim.SetBool ("Attack1", true);
     }
         noOfClicks = Mathf.Clamp (noOfClicks, 0, 3);

} }alt text

the-game-screen.png (194.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

119 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

Related Questions

Animations not importing into Unity from Blender 0 Answers

Fixing Animation calls in a combo Script 0 Answers

Help! Unity Attack Combo Chain using single button smashing 0 Answers

[2d] Moving objects one by one along another object 2 Answers

How do I rotate specific joints/bones using a script? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges