C# unity 3d:如何在插槽上逐个收集和放置5个衍生对象

C# unity 3d:如何在插槽上逐个收集和放置5个衍生对象,c#,unity3d,scripting,C#,Unity3d,Scripting,我的unity c#代码有问题,对象在某个位置生成,以及 如何使用插槽编号和填充计数器拾取和放置在每个插槽上生成的对象,以便我能够从插槽中拾取种子并将其逐个放置在其他插槽中,并计算插槽中的当前种子数 同时也使它成为一款有计时器的回合制游戏 using System.Collections; using System.Collections.Generic; using UnityEngine; public class slotProperty : MonoBehaviour { p

我的unity c#代码有问题,对象在某个位置生成,以及 如何使用插槽编号和填充计数器拾取和放置在每个插槽上生成的对象,以便我能够从插槽中拾取种子并将其逐个放置在其他插槽中,并计算插槽中的当前种子数 同时也使它成为一款有计时器的回合制游戏

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

public class slotProperty : MonoBehaviour 
{
    public bool isFilled = false;
    [SerializeField] private int fillCounter;
    public SlotManager slotManager;
    public Transform spawnLocation;
    [SerializeField] private int slotNum;
    // public GameObject slots;

    private void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.gameObject.name == "slot_1")
            if (!isFilled)
                //To spawn 5 seeds on slot 1 - 7

                if (slotNum <= 7) 
                { 
                    {
                        Instantiate(slotManager.fillAvailableBall(), spawnLocation.transform.position, Quaternion.identity);
                        fillCounter++;
                        if (fillCounter == 5)
                            isFilled = true;
                    }
                }
                //To spawn 5 seeds on slot 8 and 9

                else if (slotNum <= 9)   
                {
                    {
                        Instantiate(slotManager.fillAvailableBall(), spawnLocation.transform.position, Quaternion.identity);
                        fillCounter++;
                        if (fillCounter == 1)
                            isFilled = true;
                    }
                }

                //To spawn 5 seeds on slot 10
                else if (slotNum == 10)
                {
                    {
                        Instantiate(slotManager.fillAvailableBall(), spawnLocation.transform.position, Quaternion.identity);
                        fillCounter++;
                        if (fillCounter == 5)
                            isFilled = true;
                    }
                }
                else if(slotNum <= 20)
                {
                    {
                        fillCounter++;
                        if (fillCounter == 0)
                            isFilled = true;
                    }
                }
                else
                {

                }
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类slotProperty:单一行为
{
公共bool isFilled=false;
[SerializeField]专用整型填充计数器;
公共SlotManager SlotManager;
公共场所;
[SerializeField]私有int slotNum;
//公共游戏对象插槽;
私有void更新()
{
Ray-Ray=Camera.main.screenpointoray(输入.鼠标位置);
雷卡斯特击中;
如果(物理.光线投射(光线,出击))
{
if(hit.collider.gameObject.name==“插槽1”)
如果(!isFilled)
//在插槽1-7上生成5个种子

if(slotNum)我很难理解为什么要在每个
if-else
块中使用
{}
封闭块…但在某些实际有用的地方没有:在
if(!isFilled)
if(!isFilled)检查要在插槽上生成的数字对象之后