help with my code, i don't know what i am doing wrong

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

public class SpawnManager : MonoBehaviour
{
    [SerializeField]
    private GameObject _enemyPrefab;
    [SerializeField]
    private GameObject _enemyContainer;
    [SerializeField]
    private GameObject _TripleShotPowerUpPrefab;

    private bool _stopSpawning = false;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(SpawnEnemyRoutine());
        StartCoroutine(SpawnPowerUpRoutine());
    }

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

    IEnumerator SpawnEnemyRoutine()
    {
     while (_stopSpawning == false)
        {
            Vector3 postToSpawn = new Vector3(Random.Range(-8f, 8f), 7, 0);
            GameObject newenemy = Instantiate(_enemyPrefab, postToSpawn, Quaternion.identity);
            newenemy.transform.parent = _enemyContainer.transform;
            yield return new WaitForSeconds(5.0f);
        }

     IEnumerator SpawnPowerUpRoutine()
        {
            while (_stopSpawning == false)
            {
                Vector3 postToSpawn = new Vector3(Random.Range(-8f, 8f), 7, 0);
                Instantiate(_TripleShotPowerUpPrefab, postToSpawn, Quaternion.identity);
                yield return new WaitForSeconds(Random.Range(3, 8));
            }

        }
      
}
    public void OnPlayerDeath()
    {
        _stopSpawning = true;
    }

}

[ICODE][/ICODE]

Error CS0103 The name ‘SpawnPowerUpRoutine’ does not exist in the current context

Warning CS8321 The local function ‘SpawnPowerUpRoutine’ is declared but never used

I have tried to figure it out but just can’t any help would nice

You have some wayward curly braces. Right now, SpawnPowerUpRoutine is inside of SpawnEnemyRoutine. Take a look around and count the curly braces. You should be able to spot the problem then.

Edit:
If you are working in Visual Studio, this shortcut combo will format the current document and help make the problem clearer.
ctr+a
ctr+k,f ← Hold the control key, then press k followed by f while keeping control down

The indentation is deceiving you.

1 Like

Move line 49 curly bracket to line 37 :slight_smile:

thank you so much it worked

thanks it worked. big help

I’m stuck in the same code as you. Vector3 and Quaternion seem highlighted with errors. Rings a bell?

Thanks!

5895977–628871–Spawn_manager.cs (1.43 KB)

i dont have a curly bracet in line 49

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using JetBrains.Annotations;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Assertions;
using Debug = UnityEngine.Debug;

public class player : MonoBehaviour
{
private bool jumpKeyWasPressed;
private float horizontalInput;
private Rigidbody rigidbodyComponent;
private bool isGrounded;

// Start is called before the first frame update
void Start()
{
rigidbodyComponent = GetComponent();
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
jumpKeyWasPressed = true;
}

horizontalInput = Input.GetAxis(“Horizontal”);
}

// FixedUpdate is called once every physic update
private void FixedUpdate()
{
if (!isGrounded)
{
return;
}

if (jumpKeyWasPressed)
{
rigidbodyComponent.AddForce(Vector3.up * 5, ForceMode.VelocityChange);
jumpKeyWasPressed = false;
}

rigidbodyComponent.velocity = new Vector3(horizontalInput, rigidbodyComponent.velocity.y, 0);

void OnCollisionEnter(Collision collision)
{
isGrounded = true;
}

void OnCollisionExit(Collision collision)
{
isGrounded = false;
}
}
}

can someone help me remove this CS8321 warning

Please don’t necro-post. You likely just have typos but nobody can read your code because you failed to format it properly. Here’s how to fix your typing mistakes:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error or warning message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

When you have an actual problem that isn’t just inaccurate typing, here is how to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

If you ever post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379