예제 #1
0
    void RespawnObject(SpawnableObject obj)
    {
        //  Debug.LogError("Respawning " + obj.gameObject.name);

        if (obj.ReassignRandomPositionOnRespawn || obj.SpawnType == SpawnType.PLAYER_FORWARD)
        {
            switch (obj.SpawnType)
            {
            case SpawnType.PLAYER_FORWARD:
                //      Debug.LogError("Trying to respawn player_forward");
                Transform pTransform = GameSceneManager.Instance.GameState.Player.transform;
                Vector3   forwardPos = (pTransform.forward * obj.PlayerForwardDistance) + pTransform.position;
                if (!GetWalkablePosition(forwardPos, 3.0f, out obj.AssignedPosition))
                {
                    //     Debug.LogError("Can't respawn object " + obj.gameObject.name + " due to no walkable position found");
                    return;
                }
                break;

            case SpawnType.RANDOM_MAP_POSITION:
                obj.AssignedPosition = GetRandomMapPosition();
                break;

            case SpawnType.RANDOM_PREDEFINED_POSITION:
                obj.AssignedPosition = GetRandomPredefinedPosition();
                break;
            }
        }

        if (obj.AssignedPosition == null || obj.AssignedPosition == Vector3.zero)
        {
            //  Debug.LogError("Can't respawn object " + obj.gameObject.name + " due to invalid AssignedPosition");
            return;
        }

        obj.ResetComponents();
        obj.TeleportTo(obj.AssignedPosition);
        obj.gameObject.SetActive(true);
    }