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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

The same field name is serialized multiple times...

Discussion in 'Scripting' started by gbcm18, Jun 19, 2019.

  1. gbcm18

    gbcm18

    Joined:
    Jun 7, 2019
    Posts:
    4
    Hello guys. I have 6 error: """
    The same field name is serialized multiple times in the class or its parent class.This is not supported : Base(MonoBehaviour) hiz
    The same field name is serialized multiple times in the class or its parent class.This is not supported : Base(MonoBehaviour) bicakPrefab
    The same field name is serialized multiple times in the class or its parent class.This is not supported : Base(MonoBehaviour) bicakKonum
    The same field name is serialized multiple times in the class or its parent class.This is not supported : Base(MonoBehaviour) hiz
    The same field name is serialized multiple times in the class or its parent class.This is not supported : Base(MonoBehaviour) bicakPrefab
    The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MonoBehaviour) bicakKonum
    """
    How can I fix?
    My Player Codes:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Player : Iskelet {
    6.    
    7.     private Rigidbody2D myRigidbody;
    8.     protected Animator myAnimator;
    9.     private int skor;
    10.     public Text toplamSkor;
    11.     [SerializeField]
    12.     private GameObject anahtarVar;
    13.     [SerializeField]
    14.     protected float hiz;
    15.     protected bool sagaBak;
    16.     [SerializeField]
    17.     private AudioSource altinSes;
    18.     [SerializeField]
    19.     private AudioSource anahtarSes;
    20.     private bool atak;
    21.     private bool kayma;
    22.     [SerializeField]
    23.     private Transform[] temasNoktasi;
    24.     [SerializeField]
    25.     private float temasCapi;
    26.     [SerializeField]
    27.     private LayerMask hangizemin;
    28.     private bool zeminde;
    29.     private bool zipla;
    30.     [SerializeField]
    31.     private bool havadaKontrol;
    32.     [SerializeField]
    33.     private float ziplamaKuvveti;
    34.     [SerializeField]
    35.     private GameObject bicakPrefab;
    36.     [SerializeField]
    37.     protected Transform bicakKonum;
    38.     [SerializeField]
    39.     private GameObject key1;
    40.  
    41.     public override void Start () {
    42.         base.Start ();
    43.         sagaBak = true;
    44.         skor = 0;
    45.         myRigidbody = GetComponent<Rigidbody2D> ();
    46.         myAnimator = GetComponent<Animator> ();
    47.     }
    48.  
    49.     void Update ()
    50.     {
    51.         Kontroller ();
    52.     }
    53.  
    54.     void FixedUpdate () {
    55.         float yatay = Input.GetAxis ("Horizontal");
    56.         zeminde = Zeminde ();
    57.         TemelHareketler (yatay);
    58.         YonCevir (yatay);
    59.         AtakHareketleri ();
    60.         Resetler ();
    61.  
    62.         if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.RightArrow))
    63.         {
    64.             myAnimator.SetBool ("Run", true);
    65.         }
    66.         else
    67.         {
    68.             myAnimator.SetBool ("Run", false);
    69.         }
    70.         if (Input.GetKey (KeyCode.DownArrow))
    71.         {
    72.             myAnimator.SetBool ("kayma", true);
    73.         }
    74.         else
    75.         {
    76.             myAnimator.SetBool ("kayma", false);
    77.  
    78.         }
    79.         if (Input.GetKeyDown (KeyCode.J))
    80.         {
    81.             myAnimator.SetBool ("JumpAttack", true);
    82.  
    83.         }
    84.         else
    85.         {
    86.             myAnimator.SetBool ("JumpAttack", false);
    87.         }
    88.  
    89.     }
    90.  
    91.  
    92.     private void TemelHareketler(float yatay){
    93.         if (!myAnimator.GetBool("kayma") && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("atak") && (zeminde||havadaKontrol))
    94.         {
    95.             myRigidbody.velocity = new Vector2 (yatay * hiz, myRigidbody.velocity.y);
    96.         }
    97.         if (zeminde && zipla) {
    98.             zeminde = false;
    99.             myRigidbody.AddForce (new Vector2 (0, ziplamaKuvveti));
    100.             myAnimator.SetTrigger ("Jump");
    101.         }
    102.         if (kayma && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide"))
    103.         {
    104.             myAnimator.SetBool ("kayma", true);
    105.         }
    106.         else if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide"))
    107.         {
    108.             myAnimator.SetBool ("kayma", false);
    109.         }
    110.     }
    111.     private void AtakHareketleri()
    112.     {
    113.         if (atak && zeminde && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag ("atak"))
    114.         {
    115.             myAnimator.SetTrigger ("atak");
    116.             myRigidbody.velocity = Vector2.zero;
    117.         }
    118.     }
    119.     private void Kontroller()
    120.     {
    121.         if (Input.GetKeyDown (KeyCode.Space))
    122.         {
    123.             atak = true;
    124.         }
    125.         if (Input.GetKeyDown (KeyCode.UpArrow)) {
    126.             zipla = true;
    127.  
    128.         }
    129.         if (Input.GetKeyDown (KeyCode.K))
    130.         {
    131.             myAnimator.SetTrigger ("firlat");
    132.  
    133.         }
    134.     }
    135.  
    136.     private void YonCevir(float yatay)
    137.     {
    138.         if (yatay > 0 && !sagaBak || yatay < 0 && sagaBak)
    139.         {
    140.             sagaBak = !sagaBak;
    141.             Vector3 yon = transform.localScale;
    142.             yon.x *= -1;
    143.             transform.localScale = yon;
    144.         }
    145.     }
    146.     void OnCollisionEnter2D(Collision2D other){
    147.         if (other.gameObject.tag == "kutucuk" && this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide"))
    148.         {
    149.             other.gameObject.SetActive (false);
    150.             key1.SetActive (true);
    151.  
    152.         }
    153.         if (other.gameObject.tag == "para11") {
    154.             other.gameObject.SetActive (false);
    155.             skor = skor + 100;
    156.             SkorAyarla (skor);
    157.             altinSes.Play ();
    158.  
    159.         }
    160.  
    161.  
    162.         if (other.gameObject.tag == "key") {
    163.             other.gameObject.SetActive (false);
    164.             anahtarVar.SetActive (true);
    165.             anahtarSes.Play ();
    166.         }
    167.  
    168.     }
    169.  
    170.     void SkorAyarla(int count)
    171.     {
    172.         toplamSkor.text= "Skor:" + count.ToString();
    173.  
    174.     }
    175.  
    176.     private void Resetler(){
    177.         atak = false;
    178.         kayma = false;
    179.         zipla = false;
    180.     }
    181.     private bool Zeminde ()
    182.     {
    183.         if (myRigidbody.velocity.y <= 0)
    184.         {
    185.             foreach (Transform nokta in temasNoktasi)
    186.             {
    187.                 Collider2D[] colliders = Physics2D.OverlapCircleAll (nokta.position, temasCapi, hangizemin);
    188.                 for (int i = 0; i < colliders.Length; i++)
    189.                 {
    190.                     if (colliders [i].gameObject != gameObject)
    191.                     {
    192.                         return true;
    193.                     }
    194.                 }
    195.             }
    196.         }
    197.         return false;
    198.     }
    199.     public override void BicakFirlat(int value) {
    200.         if (!zeminde && value == 1 || zeminde && value == 0) {
    201.             if (sagaBak) {
    202.                 GameObject klonBicak = (GameObject)Instantiate (bicakPrefab, bicakKonum.position, Quaternion.Euler (new Vector3 (0, 0, -90)));
    203.                 klonBicak.GetComponent<Bicak> ().Initialize (Vector2.right);
    204.  
    205.             }
    206.             else
    207.             {
    208.                 GameObject klonBicak = (GameObject)Instantiate (bicakPrefab, bicakKonum.position, Quaternion.Euler (new Vector3 (0, 0, 90)));
    209.                 klonBicak.GetComponent<Bicak> ().Initialize (Vector2.left);
    210.             }
    211.         }
    212.     }
    213. }
    My Iskelet Codes:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public abstract class Iskelet : MonoBehaviour {
    5.  
    6.  
    7.     public Animator myAnimator { get; private set;}
    8.     [SerializeField]
    9.     protected Transform bicakKonum;
    10.     [SerializeField]
    11.     protected float hiz;
    12.     protected bool sagaBak;
    13.     [SerializeField]
    14.     private GameObject bicakPrefab;
    15.     public bool Atak {
    16.         get;
    17.         set;
    18.     }
    19.  
    20.     public void YonDegistir ()
    21.     {
    22.         sagaBak = !sagaBak;
    23.         transform.localScale = new Vector3 (transform.localScale.x * -1, 1, 1);
    24.     }
    25.  
    26.     public virtual void Start () {
    27.         sagaBak = true;
    28.         myAnimator = GetComponent<Animator> ();
    29.     }
    30.    
    31.  
    32.  
    33.  
    34.  
    35.  
    36.  
    37.  
    38.     void Update () {
    39.    
    40.     }
    41.     public virtual void BicakFirlat(int value) {
    42.        
    43.         if (sagaBak) {
    44.             GameObject klonBicak = (GameObject)Instantiate (bicakPrefab, bicakKonum.position, Quaternion.Euler (new Vector3 (0, 0, -90)));
    45.             klonBicak.GetComponent<Bicak> ().Initialize (Vector2.right);
    46.             }
    47.         else
    48.             {
    49.             GameObject klonBicak = (GameObject)Instantiate (bicakPrefab, bicakKonum.position, Quaternion.Euler (new Vector3 (0, 0, 90)));
    50.             klonBicak.GetComponent<Bicak> ().Initialize (Vector2.left);
    51.             }
    52.  
    53.     }
    54. }
    55.  
     
  2. Ermanator

    Ermanator

    Joined:
    Mar 5, 2022
    Posts:
    1
    I think the error is because you've already defined those variables in Iskelet. so when Player Inherits Iskelet you have multiple instances of the same variable. To resolve you need to only define them in one of the classes.