Search Unity

error CS0029

Discussion in 'Scripting' started by HarryWhitelegg02, Mar 19, 2020.

  1. HarryWhitelegg02

    HarryWhitelegg02

    Joined:
    Mar 11, 2020
    Posts:
    39
    For some reason, my script gives this error, the line is meant to activate a checkpoint in my game but doesn't seem to work.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Checkpoint : MonoBehaviour
    6. {
    7.     public GameMaster gameMaster;
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         gameMaster = FindObjectOfType<GameMaster>();
    13.     }
    14.  
    15.     void OnTriggerEnter2D(Collider other)
    16.     {
    17.         if (other.gameObject.tag == "Player")
    18.         {
    19.             gameMaster.spawnPoint = gameObject; ("this is the line that has the issue")
    20.         }
    21.     }
    22. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Dead : MonoBehaviour
    6. {
    7.     public GameMaster gameMaster;
    8.  
    9.  
    10.     void OnTriggerEnter2D(Collider2D other)
    11.     {
    12.         if (other.gameObject.tag == "Player")
    13.         {
    14.            
    15.                 Debug.Log("Died");
    16.  
    17.                 gameMaster.RespawnPlayer();
    18.  
    19.                 other.gameObject.GetComponent<PlayerMovement>().Die();
    20.  
    21.         }
    22.  
    23.     }
    24. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GameMaster : MonoBehaviour
    6. {
    7.     public static GameMaster gm;
    8.     public Transform playerPrefab;
    9.     public Transform spawnPoint;
    10.  
    11.  
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         if (gm == null)
    17.         {
    18.             gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    19.         }
    20.  
    21.     }
    22.  
    23.    
    24.  
    25.     public void RespawnPlayer()
    26.     {
    27.         Debug.Log("Player Respawn");
    28.         playerPrefab.transform.position = spawnPoint.transform.position;
    29.     }
    30.  
    31. }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Please copy and paste the entire error message. We don't have error codes memorized, plus the error message contains more information (e.g. line numbers).
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    You're trying to assign a GameObject object to "gameMaster.spawnPoint" which is of type "Transform". C# won't let you perform that assignment because the types are wrong.

    Probably you just need to change your assignment to `gameMaster.spawnPoint = gameObject.transform;`