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 tiyyargee · Dec 14, 2016 at 02:31 PM · c#animatorscript.animator controller

how i can set attack back to false ?

hello guys i have a problem to set attack back to false in my melee combat rpg game that im trying to make i have 2 scripts attached to a player first is basic movement script and second script for attacking all i want is when the player start to do attack animations i want it to stop moving, and when it finish the attacking i want it to go back to move , all done but i dont know and i cant set attack back to false so the player can move my scripts: using UnityEngine; using System.Collections;

public class player_motion123 : MonoBehaviour {

 public Animator anim;
 //public Transform center_point;
 public Quaternion newrotation;
 public float smooth = 0.05f;


 public float speed;
 public CharacterController controller;
 public static bool ismoving=false;
 public static bool isRunning=false;

 public Transform cam;
 bool grounded;

 // jump


 private float verticalVelocity;
 public float gravity;
 public float JumpForce;
 public bool jumping;







 void Start()
 {
     
 }




 void Update ()
 {
     
     float v = Input.GetAxis ("Vertical");

     float h = Input.GetAxis ("Horizontal");

     if (player_Sword_Attack.attacking == false) 
     {
         Move (h, v);
         Run (h, v);
         jump ();
     }




 }



 void Move(float h ,float v)

 {
     
     if (h != 0f || v != 0f)
     {
         
         rotate (v, h);
         controller.SimpleMove (transform.forward * speed);
         anim.SetFloat ("Speed", 0.5f);
         ismoving = true;
     } else {
         anim.SetFloat ("Speed",0);
         ismoving = false;
     }

 }


 void Run(float h, float v)
 {
     if (ismoving && Input.GetKey (KeyCode.LeftShift)) {

         rotate (v, h);
         controller.SimpleMove (transform.forward * speed * 2);
         anim.SetFloat ("Speed", 1);
         isRunning = true;
     }
     else if (ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
         anim.SetFloat ("Speed", 0.5f);
         isRunning = false;
     }
     else if (!ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
         anim.SetFloat ("Speed", 0);
         isRunning = false;
     }



 }




 void jump()
 {

     if (controller.isGrounded) 
     {
         verticalVelocity = -gravity * Time.deltaTime;
         if (Input.GetKeyDown (KeyCode.Space)) 
         {
             anim.SetBool ("Jumping", true);

             verticalVelocity = JumpForce;
             jumping = true;
             if (isRunning)
             verticalVelocity = JumpForce * 5f;
             jumping = true;

         }
     }
     else 
     {
         verticalVelocity -= gravity * Time.deltaTime;
         anim.SetBool ("Jumping",false);
         jumping = false;
     }
     Vector3 moveVector = Vector3.zero;
     moveVector.x = Input.GetAxis ("Horizontal");
     moveVector.y = verticalVelocity;
     moveVector.z = Input.GetAxis("Vertical");
     controller.Move (moveVector*Time.deltaTime);




 }







 void rotate(float v,float h) {
     if (v > 0)
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+45,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+305,0);
         }
         else
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y,0);
         }
     }
     else if (v < 0)
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+135,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+225,0);
         }
         else {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+180,0);
         }
     }
     else
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+90,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+270,0);
         }
         else {
             newrotation = transform.rotation;
         }
     }


     newrotation.x = 0;

     newrotation.z = 0;

     //We only want player to rotate in y axis
     transform.rotation = Quaternion.Slerp (transform.rotation,newrotation, smooth);

     //Slerp from player's current rotation to the new intended rotaion smoothly 
 }


} attack scripusing UnityEngine; using System.Collections;

public class player_Sword_Attack : MonoBehaviour {

 private float lastTapTime = 1;
 float tapSpeed = .3f;

 private int clickCount = 0;


 Animator anim;

 public static bool attacking=false;


 player_sword ps;








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


 }

 // 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) && ps.sword_is_equiped==true)
     {
         attacking = true;
         lastTapTime = Time.time;

         if ((Time.time - lastTapTime) < tapSpeed)
         {
             clickCount += 1;

             if(clickCount >= 3)
             {
                 attacking = true;
                 anim.SetTrigger("slash3");
                 attacking = true;
                 clickCount = 0;


             }
         }
     }

     if ((Time.time - lastTapTime) > tapSpeed) {
         if (clickCount == 2) {
             

             anim.SetTrigger("slash2");
             clickCount = 0;
         } else if (clickCount == 1) {

             anim.SetTrigger("slash");

             clickCount = 0;

         }

         clickCount = 0;
     }


     

 }




 void OnCollisionEnter(Collision collision)
 {
     if(collision.gameObject.tag=="opposite")
     {
         Debug.Log("enemy hitted");
         //GameObject.FindGameObjectWithTag("Enemy").GetComponent<enemyMove>().gethit(damage);

     }

 }

 /*bool inRange()
 {
     if (Vector3.Distance (transform.position, enemy.transform.position) < inrange)
         return true;
     else
         return false;
 }
 */

} t;

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

How can I address the Animator of a prefab from a C# script? 3 Answers

C# to set trigger on animator components of all children 3 Answers

Animations Not Working when Pressing Certain Keys 1 Answer

Editing other object's animator parameter... NullReferenceException? (VR) 0 Answers

MobController 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