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): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Checkpoint : MonoBehaviour { public GameMaster gameMaster; // Start is called before the first frame update void Start() { gameMaster = FindObjectOfType<GameMaster>(); } void OnTriggerEnter2D(Collider other) { if (other.gameObject.tag == "Player") { gameMaster.spawnPoint = gameObject; ("this is the line that has the issue") } } } Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Dead : MonoBehaviour { public GameMaster gameMaster; void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { Debug.Log("Died"); gameMaster.RespawnPlayer(); other.gameObject.GetComponent<PlayerMovement>().Die(); } } } Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameMaster : MonoBehaviour { public static GameMaster gm; public Transform playerPrefab; public Transform spawnPoint; // Start is called before the first frame update void Start() { if (gm == null) { gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>(); } } public void RespawnPlayer() { Debug.Log("Player Respawn"); playerPrefab.transform.position = spawnPoint.transform.position; } }
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).
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;`