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 /
avatar image
1
Question by dudedude123 · Jul 01, 2018 at 06:55 PM · inputcontrollermecanim

Mecanim controler problem

I had written a script with the intention to use an xbox controller (I'm using a 360 controller)

     public Image healthbar;
     public Text ratioHealthText;
 
     public Image staminabar;
     public Text ratioStaminaText;
 
     private float ratio;
 
     private const int maxStamina = 100;
     private const int maxHealth = 100;
 
     public float currentHealth = maxHealth;
     public float currentStamina = maxStamina;
 
     float walk;
     float punch;
     float leftright;
     float headbody;
     float block;
     float impact;
     float ko;
 
 
     public AudioClip swing;
     public AudioClip hit;
     public AudioClip groan;
     public AudioClip faint;
     
     private AudioSource source;
     private float volLowRange = .5f;
     private float volHighRange = 1.0f;
 
     public GameObject pauseScreen;
 
     private bool pauseEnabled = false;
     
 
     private Animator animator;
     private CharacterController controller;
     private Vector3 moveVector;
     public Collider[] attackHitBoxes;
 
     public int speed = 0;
     public int power = 0;
     public int endurance = 0;
 
 
 
     // Use this for initialization
     void Start () {
         controller = GetComponent<CharacterController>();
         animator = GetComponent<Animator>();
         source = GetComponent<AudioSource>();
         Healthbar();
         pauseEnabled = false;
         Time.timeScale = 1;
         AudioListener.volume = 1;
         Cursor.visible = false;
     }
     
     // Update is called once per frame
     private void Update () {
 
 
 
         walk = Input.GetAxis("Main_Vertical");
         punch = Input.GetAxis("Secondary_Vertical");
         leftright = Input.GetAxis("Secondary_Horizontal");
         headbody = Input.GetAxis("Left_Trigger");
         block = Input.GetAxis("Right_Trigger");
 
 
 
         //check if pause button (escape key) is pressed
         if (Input.GetButtonDown("Start_Button"))
         {
 
             //check if game is already paused        
             if (pauseEnabled == true)
             {
                 //unpause the game
                 pauseEnabled = false;
                 Time.timeScale = 1;
                 AudioListener.volume = 1;
                 pauseScreen.SetActive(false);
             }
 
             //else if game isn't paused, then pause it
             else if (pauseEnabled == false)
             {
                 pauseEnabled = true;
                 AudioListener.volume = 0;
                 Time.timeScale = 0;
                 pauseScreen.SetActive(true);
             }
         }
         
         float vol = Random.Range(volLowRange, volHighRange);
 
         if (punch > 0.01)
         {
             Attack(attackHitBoxes[0]);
             source.PlayOneShot(swing, vol);
         }
 
         animator.SetFloat("Walk", walk);
         animator.SetFloat("Punch", punch);
         animator.SetFloat("LeftRight", leftright);
         animator.SetFloat("Block", block);
         animator.SetFloat("HeadBody", headbody);
         animator.SetFloat("Impact", impact);
         animator.SetFloat("KO", ko);
 
     }
 
 
     private void Healthbar()
     {
 
     
     healthbar.rectTransform.localScale = new Vector3(ratio, 1, 1);
         ratioHealthText.text = (ratio*100).ToString("0") + '%';
     }
 
     private void Staminabar()
     {
 
 
         staminabar.rectTransform.localScale = new Vector3(ratio, 1, 1);
         ratioStaminaText.text = (ratio * 100).ToString("0") + '%';
     }
 
     private void Damage(float damage)
     {
 
         currentHealth -= damage;
         if (currentHealth < 0)
         {
             currentHealth = 0;
             ko = 1f;
         }
         Healthbar();
     }
 
     private void Heal(float heal)
     {
         currentHealth -= heal;
         Healthbar();
     }
 
     private void DrainStamina(float drain)
     {
         currentStamina -= drain;
     }
 
     private void ReplenishStamina(float replenish)
     {
         currentStamina -= replenish;
     }
 
     private void Attack(Collider col)
     {
         Collider[] cols = Physics.OverlapBox(col.bounds.center, col.bounds.extents, col.transform.rotation, LayerMask.GetMask("Hitbox"));
 
         
 
         foreach (Collider c in cols)
         {
             if (c.transform.parent.parent == transform)
                 continue;
             float vol = Random.Range(volLowRange, volHighRange);
             float damage = 0;
             float heal = 0;
             switch (c.name)
             {
                 case "Head":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 10;
                     heal = 5;
                     impact = 1f;
                     break;
                 case "Torso":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 10;
                     heal = 5;
                     impact = .3f;
                     break;
                 case "LHand":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
                 case "RHand":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
 
                 case "HeadHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 30;
                     impact = 1f;
                     break;
                 case "SpineHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 10;
                     impact = .3f;
                     break;
                 case "Spine1HD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 10;
                     impact = .3f;
                     break;
                 case "LeftArmHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
                 case "RightArmHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
                 case "LeftHandHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
                 case "RightHandHD":
                     source.PlayOneShot(hit, vol);
                     source.PlayOneShot(groan, vol);
                     damage = 0;
                     break;
 
             }
 
 
         }
     }
     public void BoxerSelect()
     {
         Application.LoadLevel("Setup");
     }
 
     public void Restart()
     {
         
     }
 
     public void Quit()
     {
         Application.Quit();
     }
 

for some reason I cant manage to get it to work with animations, does anybody else have this problem?

alt text

2018-06-02-21h23-03.png (42.0 kB)
2018-06-02-21h23-26.png (24.3 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.

Follow this Question

Answers Answers and Comments

113 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

Related Questions

How would I use Mecanim to holster or draw a weapon? (C#) 1 Answer

Virtual joystick in the new input system 0 Answers

When I try to bind a key in the new input system bind dropdown, nothing shows (linux) 2 Answers

Multiple x360 controllers get wrong IDs assigned. 2 Answers

Detect if an XBOX 360 controller is plugged in 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