• 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 /
This question was closed Oct 09, 2020 at 07:46 PM by TwiningLion1357 for the following reason:

Other

avatar image
0
Question by TwiningLion1357 · Sep 04, 2020 at 08:07 PM · collideranimatordisableragdollenable

Ragdoll help

Hello, I am trying to make a script where the enemy turns into a ragdoll after his health is less than or equal to 0. Also, the enemy has an animation, so i'm trying to make it where the ragdoll gets disabled and the animator gets enabled, then vice versa when he dies. But I keep getting these errors that I don't under stand! If anyone can help, here is my script and errors:alt text

using UnityEngine; using System.Collections; using System.Collections.Generic; public class Enemy : MonoBehaviour{ public Animator death; public float health = 50f; void Start() { setRigidbodystate(true); setColliderstate(false); } public void TakeDamage(float amount) { health -= amount; if (health <= 0f) { Die(); } } public void Die() { //death.SetTrigger("IsDead"); GetComponet<Animator>().enabled = false; setRigidbodystate(false); setColliderstate(true); } void setRigidbodystate(bool state) { Rigidbody[] rigidbodies = GetComponentInChildren<Rigidbody>(); foreach (Rigidbody rigidbody in rigidbodies) { rigidbody.isKinematic = state; } GetComponet<Rigidbody>().isKinematic = !state; } void setColliderstate(bool state) { Colliders[] colliders = GetComponentInChildren<Collider>(); foreach (Collider collider in colliders) { collider.enabled = state; } GetComponet<Collider>().enabled = !state; } }

screenshot-12.png (152.9 kB)
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 BenWiller1989 · Sep 06, 2020 at 02:38 AM 0
Share

Do me a favor and set the Rigidbody and colliders arrays as normal variables. Do not just create them in your methods. That seems to be the problem.

avatar image TwiningLion1357 BenWiller1989 · Sep 06, 2020 at 07:44 PM 0
Share

@BenWiller1989 Thanks for helping me with this, but how might I do what you said? I'm not necessarily the person who can take plain text, and turn it into code. Do you $$anonymous$$d pasting instructions for doing this?

1 Reply

  • Sort: 
avatar image
0

Answer by BenWiller1989 · Sep 04, 2020 at 09:18 PM

First of all, change Rigidbody and collider to "GetComponentsInChildren", not "GetComponentInChildren". You'd like to fill an array, not assign a single variable. And wow, you are very new right?

Comment
Add comment · Show 9 · 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 TwiningLion1357 · Sep 06, 2020 at 01:26 AM 0
Share

I was following a tutorial that might be outdated, I guess it is. Here is the tutorial: https://www.youtube.com/watch?v=zjuI5Jdzjxo&t=197s

avatar image TwiningLion1357 · Sep 06, 2020 at 01:26 AM 0
Share

yeah, i'm new

avatar image BenWiller1989 TwiningLion1357 · Sep 06, 2020 at 01:32 AM 0
Share

Yeah, how many errors did disappear after changing thing according to my advice?

avatar image TwiningLion1357 BenWiller1989 · Sep 06, 2020 at 01:34 AM 0
Share

i'm trying it now

Show more comments
avatar image TwiningLion1357 · Sep 06, 2020 at 01:31 AM 0
Share

Are you able to read the code? on my screen, it's all jumbled up with no ''return'' spaces

avatar image BenWiller1989 TwiningLion1357 · Sep 06, 2020 at 01:37 AM 0
Share

I am, I made ragdolls myself, so I know, what you're trying. But we need to do this step by step. Just replace the GetComponentInChildren with GetComponentsInChildren and report back, what changed.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

212 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 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 do I disable all rigidbodies and colliders in a scene in unity? 2 Answers

Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer

Enable/disable animation 0 Answers

How to change settings to a rigidbody when adding it to a gamobject? 2 Answers

keep collider disabled even when the player re-enter the scene 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