简体   繁体   English

Unity-Character 未生成

[英]Unity-Character not spawning

I am having trouble in spawning a character in Unity.我在 Unity 中生成角色时遇到问题。 This is my LoadCharacter script.这是我的 LoadCharacter 脚本。 The Debug.Log confirms that selectedCharacter has the expected value Debug.Log 确认 selectedCharacter 具有预期值

using UnityEngine;

public class LoadCharacter : MonoBehaviour
{

    public GameObject[] characterPrefabs;
    public Transform spawnPoint;

    void Start()
    {
        int selectedCharacter = PlayerPrefs.GetInt("selectedCharacter");
        GameObject prefab = characterPrefabs[selectedCharacter];
        GameObject clone = Instantiate(prefab, spawnPoint.position, Quaternion.identity);
        Debug.Log(prefab.name);
    }
}

and below are printscreens of the scene where I want to spawn the character下面是我想要生成角色的场景的打印屏幕

我的游戏经理

我的出生点(白色圆圈)

游戏模式

What is the problem?问题是什么?

That's probably because of you didn't set a parent for your Instantiated object.这可能是因为您没有为您的实例化对象设置父级。 Your SpawnPoint is a child of a parent but instantiated object is not.您的 SpawnPoint 是父级的子级,但实例化对象不是。 That's may be the problem.这可能就是问题所在。

If you don't know how to do it, you can read the documentation right here.如果您不知道如何操作,可以在此处阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM