简体   繁体   中英

Curly brackets not connecting properly

This is my code. Tried repasting the code. And multiple other things like writing the function again.

The brackets wont connect(at the start and the end of the code) when I make new function. The closing bracket from new function will jump to the one that summarizes the whole code. Even placing it properly does nothing. Thanks in advance.

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

public class Shooter : MonoBehaviour
{
    [SerializeField] GameObject projectile;
    [SerializeField] Transform gunPos;
    public void Fire()
    {
        if (!gunPos) { return; }
        GameObject projectileInstance = Instantiate(projectile, gunPos.transform.position, Quaternion.identity) as GameObject;
    }

    private void SetLaneSpawner()
    {
        public AttackerSpawner[] spawners = FindObjectsOfType<AttackerSpawner>();
    }

    private void Start()
    {
        SetLaneSpawner();
    }

    public void Update()
    {
        if (null)
        {
            Debug.Log("pew pew");
            //TODO attack animation
        }
        else
        {
            Debug.Log("wait");
            //TODO idle animation
        }
    }  


}

The error is in the line:

public AttackerSpawner[] spawners = FindObjectsOfType<AttackerSpawner>();

// Remove the public so it becomes.

AttackerSpawner[] spawners = FindObjectsOfType<AttackerSpawner>();

Accessibility modifiers (public, private, etc) can only be applied at the class and property level. You cannot use them inside a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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