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

i have many error please help me

Discussion in 'Scripting' started by GoldenMine12, Oct 24, 2020.

  1. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    i have many errors in my code that i will list bellow with the code please help me:

    Assets\scripts\RagdollDeath.cs(5,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'RagdollDeath'

    Assets\scripts\RagdollDeath.cs(13,14): error CS0111: Type 'RagdollDeath' already defines a member called 'Start' with the same parameter types

    Assets\scripts\RagdollDeath.cs(33,14): error CS0111: Type 'RagdollDeath' already defines a member called 'ToggleRagdoll' with the same parameter types

    Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name 'SerializedFieldAttribute' could not be found (are you missing a using directive or an assembly reference?)

    Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name 'SerializedField' could not be found (are you missing a using directive or an assembly reference?)


    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class RagdollDeath : MonoBehaviour
    7. {
    8.     [Header("References")]
    9.     [SerializeField] private Animator animator = null;
    10.  
    11.     private Rigidbody[] ragdollBodies;
    12.     private Collider[] ragdollColloders;
    13.  
    14. private void Start()
    15. {
    16.     ragdollBodies = GetComponentsInChildren<Rigidbody>();
    17.     ragdollColliders = GetComponentsInChildren<Collider>();
    18.  
    19.     ToggleRagdoll(False);
    20.  
    21.     Invoke(nameof(Die), 5f);
    22. }
    23.  
    24. private void Die()
    25. {
    26.     ToggleRagdoll(true);
    27.  
    28.     foreach(Rigidbody rb in ragdollBodies)
    29.     {
    30.         rb.AddExplosionForce(107f, new Vector3(-1f, 0.5f, -1f), 5f, 0f, ForceMode.Impulse);
    31.     }
    32. }
    33.  
    34. private void ToggleRagdoll(bool state)
    35. {
    36.     animator.enabled = !state;
    37.  
    38.     foreach(Rigidbody rb in ragdollBodies)
    39.     {
    40.         rb.isKinematic = !state;
    41.     }
    42.  
    43.     foreach (Collider collider in ragdollColliders)
    44.     {
    45.         collider.enabled = state;
    46.     }
    47. }
    48.  
    49.  
    50. }
    51.  
    52. [code]
     
  2. VishwasGagrani

    VishwasGagrani

    Joined:
    May 12, 2018
    Posts:
    81
    Most probably you have got two or more script files with the same name "RagdollDeath.cs" . Search for all the scripts in your project if the name is duplicate.
     
  3. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    now i have 2 errors:

    Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name 'SerializedFieldAttribute' could not be found (are you missing a using directive or an assembly reference?)


    Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name 'SerializedField' could not be found (are you missing a using directive or an assembly reference?)