使列表可拖放

时间:2020-11-11 12:23:28

标签: c# list unity3d drag-and-drop instance

我正在建立一个足球经理模拟游戏。我有一个玩家列表,当游戏开始时,使用PlayerDisplayPrefabs将玩家实例化到SquadList中。我希望此SquadList可拖放,并具有将球员及其统计数据交换进一队的能力。

我已经将拖放功能添加到了Prefab中,但是为了添加拖放功能,我需要将每个Prefab实例放到其自己的面板中,而不是SquadList面板中。

但是,如果我将着陆面板放到SquadList面板上,我的列表将位于这些面板下方而不是顶部。

This is what it looks like at the moment. I would like each item to be instanced into its own landing spot rather than below them

Thia是我用来将列表实例化到SquadDisplay面板中的代码。

using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;


public class SquadDisplay : MonoBehaviour
{

public Transform targetTransform;
public PlayerDisplay playerDisplayPrefab;
public List<Player> items = new List<Player>();



// Start is called before the first frame update
void Start()
{
        foreach (Player item in items)
    {
        PlayerDisplay display = (PlayerDisplay)Instantiate(playerDisplayPrefab);
        display.transform.SetParent(targetTransform, false);
        display.Prime(item);
    }
}

// Update is called once per frame
void Update()
{
   
}

}

有什么想法吗?谢谢JP

1 个答案:

答案 0 :(得分:-1)

您正在设置父级,但从不更改实际变换位置不是您想要的吗?