Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help :\ how to create a corpse???

Discussion in 'Scripting' started by NoNameGuy, May 10, 2016.

  1. NoNameGuy

    NoNameGuy

    Joined:
    Aug 26, 2015
    Posts:
    3
    I am a beginner in unity, and wanted when the enemy was destroyed he created the corpse with variable corpse_type = enemy_type

    Code Of Enemy

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Inimigo_script : MonoBehaviour {
    5.  
    6.     //HP
    7.     public int Health ;
    8.     public GameObject blood;
    9.     public GameObject Corpo ;
    10.     public int enemy_type = Random.Range(0,5);
    11.  
    12.     void Update(){
    13.         if(Health<=0){
    14.             death();
    15.         }
    16.     }
    17.      
    18.         void death(){
    19.             Instantiate(Corpo,transform.position,transform.rotation);
    20.             Instantiate(blood,transform.position,transform.rotation);
    21.             Destroy(gameObject);
    22.         }
    23.          
    24.     }
    Code Of Enemy Corpse

    Code (CSharp):
    1. public class Corpse_Script : MonoBehaviour{
    2.  
    3.     public int corpse_type  ;
    4.     public Animator Animador ;
    5.  
    6. }
    Example
    if the enemy variable type is equal to 2
    the variable corpse_type will equal 2
     
  2. Lecressman

    Lecressman

    Joined:
    May 4, 2016
    Posts:
    2
  3. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    You could setup a Dictionary that maps corpse_type to a GameObject, then use it to instantiate the corpses. Following @Lecressman suggestion, this dictionary could be part of a game manager.