• 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
0
Question by KINDOK · Jun 04, 2015 at 01:59 PM · c#scripting problemragdollenemyaizombie

Make a ragdoll in c#?

I have this script and I'm trying to make that when the enemy is dead he is replace by a ragdoll and not by a animation. Help me guys please!!!

The script:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyController : MonoBehaviour {
     NavMeshAgent nav;
     Transform player;
     Animator controller;
     float health;
     GameManagement game;
     CapsuleCollider capsuleCollider;
     Animator anim;
     bool isDead = false;
     // Use this for initialization
     void Awake () {
         nav = GetComponent <NavMeshAgent> ();
         player = GameObject.FindGameObjectWithTag ("Player").transform;
         controller = GetComponentInParent<Animator> ();
         game = FindObjectOfType<GameManagement> ();
         health = 20 + (1.25F * game.round);
         capsuleCollider = GetComponent <CapsuleCollider> ();
         anim = GetComponent <Animator> ();
     }
     
     // Update is called once per frame
     void Update () {
         if (!isDead) {
             nav.SetDestination (player.position);
             controller.SetFloat ("Speed", Mathf.Abs (nav.velocity.x) + Mathf.Abs (nav.velocity.z));
         }
     }
 
     void ApplyDamage(float damage)
     {
         //print (damage);
         health -= damage;
         if (health <= 0)
             Death ();
     }
 
     void Death ()
     {
         // The enemy is dead.
         isDead = true;
         nav.Stop ();
         // Turn the collider into a trigger so shots can pass trough it.
         capsuleCollider.isTrigger = true;
 
         anim.SetTrigger ("isDead");
         //GameManagement.score += 10;
         //GameManagement.monet += 10;
         // Change the audio clip of the audio source to the deat clip and play it.
         //enemyAudio.clip = deatClip;
         //enemyAudio.Play ();
 
         Destroy (gameObject, 0f);
     }
 }



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

2 People are following this question.

avatar image avatar image

Related Questions

how to make an AI damage a third person controller ? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Standard shader wrong render 0 Answers

How can i show the ui button only when pressing on the escape key ? 2 Answers

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