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 shadowpuppet · Jun 15, 2016 at 06:18 PM · randomizationattacking

random attack animations C#

NOT Mechanim and NOT java. Anything remotely pertaining to my question I have come across concern one or both of the above mentioned conditions. My attack script is C# and I love it but would like to add a variety of melee attacks rather than the enemy just cycling through his arms swinging until the player kills him. the script I have I got online and the author even commented the area where such an array would go down on line 86

public void Attack() { //Add attacking stuff here

 }

}

obviously the array would need to be mentioned up top and I tried that. No errors just nowhere to put animations. I have audio randomization scripts and trying to adapt from that. anyway, full attack script below

 using UnityEngine;
 using System.Collections;
 
 
 
 public class AttackArray : MonoBehaviour
 {
 
     public enum EnemyState{IDLE = 0, WALK = 1, RUN = 2, ATTACK = 3, KILL = 4};
     public AnimationClip enemyIdle;//setting animations
     public AnimationClip enemyWalk;//walking
     public AnimationClip enemyRun;//running/chasing
     public AnimationClip enemyAttack;//attacking player
     public AnimationClip enemyKill;//killing player
     public AnimationClip enemyDie;//killing player
     public NewEnemyHealth enemyHealth;
     public Transform Player;//adds the player to the script
     
     private int Stopped = 0;
     public int WalkingSpeed = 1;//sets the normal walking speed
     public int RunningSpeed = 5;//sets the running (chase player) speed
     public int DefaultRunningSpeed = 5;
     public int MaxDist= 8;//maximum distance the player can be before enemy stops chasing the player
     public float MinDist= 1;//how close the player can be to enemy for enemy to start chasing player
     public EnemyState currentState;
     
     private bool PlayerDetected;
     
     void Update()
     {
         if(Vector3.Distance(transform.position,Player.position) <= MaxDist)//if that object has the tag "Player"
         {
             PlayerDetected = true;
             if (PlayerDetected)
             {
                 
                 transform.LookAt(Player);//Looks at the player
                 currentState = EnemyState.RUN;
                 transform.position += transform.forward*RunningSpeed*Time.deltaTime;//follows the player
             }
         }else if(Vector3.Distance(transform.position,Player.position) > MaxDist)
         {
             RoamAround ();
         }
         if (Vector3.Distance (transform.position,Player.position) < MinDist)
         {
             currentState = EnemyState.ATTACK;
             Attack ();
             
         }
         
         if (currentState == EnemyState.IDLE)
         {
             //print ("The enemy is idle.");
             GetComponent<Animation>().CrossFade (enemyIdle.name);
         }
         else if (currentState == EnemyState.WALK)
         {
             
             GetComponent<Animation>().CrossFade (enemyWalk.name);
         }
         else if (currentState == EnemyState.RUN)
         {
             
             
             GetComponent<Animation>().CrossFade (enemyRun.name);
             RunningSpeed = DefaultRunningSpeed;
         }
         else if (currentState == EnemyState.ATTACK)
         {
             
             GetComponent<Animation>().CrossFade (enemyAttack.name);
             RunningSpeed = Stopped;
         }
         else if (currentState == EnemyState.KILL)
         {;
             
             GetComponent<Animation>().CrossFade (enemyKill.name);
         }
         
     }
     void RoamAround()
     {
         currentState = EnemyState.IDLE;//Add other RoamAround stuff here
     }
     public void Attack()
     {
         //Add attacking stuff here
         //Application.LoadLevel ("GameOver");
     }
 }
 
 
 
 
Comment
Add comment · Show 1
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 zaid87 · Jun 16, 2016 at 04:06 AM 0
Share

Just want to confirm something, is the attack playing right now, and you're just want to add more attack animation to it? If yes, you just need to create a function that selects an animation's name from a set of attack animations. and return it to be used in line 72.

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

59 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

Related Questions

For loop with two variables 0 Answers

how to randomly move each generated clone? 0 Answers

How do create multiple semi unique objects form a singular prefab or template? 1 Answer

Charecter keeps playing walking animation after punching 0 Answers

door with keycode entry - random 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