【问题标题】:Make a list drag and droppable使列表可拖放
【发布时间】:2021-02-23 10:08:05
【问题描述】:

我正在构建一个足球经理模拟游戏。我有一个玩家列表,当游戏开始时,使用 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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 嗨 tomasz。最初是这样,但我现在想要一个包含 15 个插槽的小队列表,然后将每个玩家实例化到自己的单个插槽中。我可以设置带有 15 个着陆槽的小队列表,如果我将目标变换设置为第一个槽,它会将第一个项目放在那里,但是我如何让它把第二个项目放在第二个槽中,第三个放在第三个插槽等?
    • 您可以创建一个包含 15 个游戏对象的数组,这些游戏对象可能是新建立的玩家的潜在位置(在编辑器中设置这些游戏对象)。然后创建“for 循环”15 次并在其中增加“i”此循环 15 次。每次递增时,您都会实例化玩家并将其位置设置为等于 [i] 索引处的 GameObject 数组。
    • for(int i = 0; i
    猜你喜欢
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 2015-07-08
    • 1970-01-01
    相关资源
    最近更新 更多