无法将类型转换为类型c#

无法将类型转换为类型c#,c#,unity3d,transform,C#,Unity3d,Transform,所以我正在用C#制作一个unity游戏,我试图制作一个克隆然后删除它。因此,我发布的代码使玩家重生,当他重生时火花四溅。这是火花的复制品。我无法删除火花。我收到错误消息: 无法将类型unityengine.transform转换为unityengine.gameobject 通过 所以我需要知道我的代码出了什么问题,以及它为什么这样做 这就是全部代码 using UnityEngine; using System.Collections; public class GameMaster : M

所以我正在用C#制作一个unity游戏,我试图制作一个克隆然后删除它。因此,我发布的代码使玩家重生,当他重生时火花四溅。这是火花的复制品。我无法删除火花。我收到错误消息:

无法将类型unityengine.transform转换为unityengine.gameobject 通过

所以我需要知道我的代码出了什么问题,以及它为什么这样做

这就是全部代码

using UnityEngine;
using System.Collections;

public class GameMaster : MonoBehaviour {

public static GameMaster gm;

void Start () {
    if (gm == null) {
        gm = GameObject.FindGameObjectWithTag ("GM").GetComponent<GameMaster>();
    }
}

public Transform playerPrefab;
public Transform spawnPoint;
public float spawnDelay = 2;
public Transform spawnPrefab;

public IEnumerator RespawnPlayer () {
    //audio.Play ();
    yield return new WaitForSeconds (spawnDelay);

    Instantiate (playerPrefab, spawnPoint.position, spawnPoint.rotation);
   GameObject clone = Instantiate (spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
    Destroy (clone, 3f);
}

public static void KillPlayer (Player player) {
    Destroy (player.gameObject);
    gm.StartCoroutine (gm.RespawnPlayer());
}

}

出现错误是因为在执行
public Transform spawnprown预制时,预制被声明为
Transform
。因此,您将其实例化为
转换
,而不是游戏对象

要解决它,只需改变

public Transform spawnPrefab;


出现错误是因为在执行
public Transform spawnprown预制时,预制被声明为
Transform
。因此,您将其实例化为
转换
,而不是游戏对象

要解决它,只需改变

public Transform spawnPrefab;


可以实例化为
转换
,只需在销毁行中销毁它的
游戏对象

Transform clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as Transform;
Destroy(clone.gameObject, 3f);

可以实例化为
转换
,只需在销毁行中销毁它的
游戏对象

Transform clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as Transform;
Destroy(clone.gameObject, 3f);