Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class randomspawner : MonoBehaviour { 

public int spawnRadius = 30; // not sure how large this is yet..
public int agentRadius = 5; // agent's personal space
public GameObject agent; // added in Unity GUI

Vector3 originPoint;

void CreateGroup()
{
    GameObject enemy = GetRandomSpawnPoint();
    originPoint = enemy.gameObject.transform.position;

    for (int i = 0; i < groupSize; i++)
    {
        CreateAgent();
    }
}

public void CreateAgent2()
{
    float directionFacing = Random.Range(0f, 360f);

    // need to pick a random position around originPoint but inside spawnRadius
    // must not be too close to another agent inside spawnRadius

    Instantiate(agent, originPoint, Quaternion.Euler(new Vector3(0f, directionFacing, 0f)));

}
public void CreateAgent3()
{
    float directionFacing = Random.Range(0f, 360f);

    // need to pick a random position around originPoint but inside spawnRadius
    // must not be too close to another agent inside spawnRadius
    Vector3 point = (Random.insideUnitSphere * spawnRadius) + originPoint;
    Instantiate(agent, point, Quaternion.Euler(new Vector3(0f, directionFacing, 0f)));
}


}




the errors are

Assets\random spawner.cs(15,24): error CS0103: The name 'GetRandomSpawnPoint' does not exist in the current context


Assets\random spawner.cs(18,25): error CS0103: The name 'groupSize' does not exist in the current context



Assets\random spawner.cs(20,9): error CS0103: The name 'CreateAgent' does not exist in the current context


What I have tried:

i have tried to make empty game objects of these but they still dont work and im all out of options
Posted
Updated 3-Jun-22 18:30pm
Comments
RedDk 3-Jun-22 18:09pm    
Just looking at the code (so far) ... what might help is running through your declarations to see if any of them even begin to resemble some type of 'position' ie "point". I'm guessing, being new at C# myself, seeing CS0103 is bit of a shock because it looks like I'm going to have make explicit my public (or private for that matter (says a nube)) decs.

Like I said, coming from C++/C where MS compiler upgrades often break old code without any tweaks to the user interface, like intellisense functionality updates as well, perhaps NOW you add an int.

Or something.

[Edit]
Better luck looking here: https://answers.unity.com/index.html
CP is good for discussing why something's not working in your code when you can provide descriptive accounts of why what you have might not be what's right despite the "working" aspects of it.
{/Edit]

{Edit02]
Freggzample: https://answers.unity.com/search.html?f=&type=question&redirect=search%2Fsearch&sort=relevance&q=GetRandomSpawnPoint%28%29 ... all of thes posts address what one'd intimate was wrong with NOT declaring an int, a list, an array, etc ...

Just search there on a function name. This is what I tell my dentist I do when I'm having my teeth examined. And he says back to me "Ok, so being employed is a good thing"
[/EDIT02]
Richard MacCutchan 4-Jun-22 4:32am    
You have not declared or defined either GetRandomSpawnPoint or CreateAgent, or the groupSize variable.
RedDk 4-Jun-22 13:55pm    
That's your right. And did you know that definitions and declarations and data structures came from the land of assembly language? Fun facts.

1 solution

Start by looking at the error line in Visual Studio, and hover the mouse over label which is underlined in red. A small drop down will appear to the left of the error message - open it and it will give you some options for correcting the problem which may include adding using blocks, or using full type names.

If that doesn't help, I'd suggest you go back to where you got that code from, and look there - and ask a question there if you can't work it out.

We can't help you with any specifics: we have no access to the code it refers to!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900