Spawn obsolete code

hi to all
this is my code for spawn random area a enemy… but unity say me is obsolete… but working… someone can explain me why???
tnk in advance

 [SerializeField] GameObject femaleZombie;
    [SerializeField] int femaleZombieIngame;
    [SerializeField] float timerCheckfemaleZombie;

  
    [SerializeField] public Transform leftEdge;
    [SerializeField] public Transform rightEdge;
  

    void Start()
    {
        timerCheckfemaleZombie = Time.deltaTime;
        StartCoroutine(spawnEnemy(femaleZombieIngame, femaleZombie));
    }

  
    public IEnumerator spawnEnemy(int number, GameObject snail)
    {


        yield return new WaitForSeconds(timerCheckfemaleZombie);
        GameObject newEnemy = Instantiate(femaleZombie, new Vector3(Random.RandomRange(-2, 2), Random.Range(-2, 2), 0), Quaternion.identity);
        StartCoroutine(spawnEnemy(number, femaleZombie));
        femaleZombieIngame++;
        timerCheckfemaleZombie = 0;

        if (femaleZombieIngame > 3)
        {
            StopSpawn();
        }
        else
        {
            gameObject.SetActive(true);
        }
    }
    public void StopSpawn()
    {
        if (femaleZombieIngame > 3)
        {
            gameObject.SetActive(false);
        }
    }
}

Believe it or not you can get a LOT more information out of your error message and probably look up the actual API all by yourself:

The complete error / 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.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

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.

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.

Hover your mouse over both Random.RandomRange and Random.Range. You’ll find one of the two is obsolete. As Kurt mentions, always refer to the documentation.

forgive me the translator often doesn’t do its job I meant that Random.RandomRange is obsolete… but it all works correctly anyway… do you have programming problems with obsolete writing???

Random.RandomRange is the obsolete version of Random.Range, so you should use the non-obsolete version. You’re already using both methods, so you should just changes instances of the obsolete method to the current one.

It should even be in the error message “use Random.Range instead”.

Seems like there be a bit of language barrier (especially if you are using an automated translator) both in terms of English and the specific use word “obsolete” in context of software development. I understand how it can be a little confusing if one of the top dictionary meanings for word Obsolete is “no longer in use”.

It can also mean “out of date; unfashionable or outmoded”, “of a kind or style no longer current”.

If you are not familiar with the process of obsoleting old APIs and confused why it’s labelled as “obsolete” even thought thought it still works. The alternative would be if Unity simply removed without giving any warnings ahead of time, but that would break a lot of people projects. By first labelling API obsolete and only warning about it’s usage, people get more time to update their projects at their own pace with less stuff breaking during Unity upgrade. The typical timeline looks something like this

  1. API is created
  2. Unity comes up with new better API
  3. old API is marked obsolete to let Users know that they should switch to the new API
  4. after some time old API is removed

So it still works, but it might stop working or get removed in future. How long in future. It depends on each specific situation, mostly three factors how difficult it is for users to transition, whether the new API has all the same functionality as old one, how difficult it is for developers to maintain the old version of API. It might be removed in next major version, or it might take years to be removed. The new “Random.Range” function has existed at least from Unity 5.2 thats more than 5-8 years of transition period. Most likely because it’s simply an alternative name which means that while the new version is functionaly identical and it’s easy for users to transition, it’s also very low cost for Unity developers to maintain the old version. With some bigger more complex unity features which are difficult to maintain, you occasionally see a different situation where the old version becomes obsolete and stops working much more quickly. Although that’s usually in separate packages, so there is not as much removal as the old package simply becomes incompatible with newer Unity versions and stops working. You can also see situations like with new Unity UI Toolkit and UGUI. Even though maintaining UGUI is somewhat difficult, the new unity UI doesn’t have exact feature parity, and also transition from UGUI to is a lot more difficult for the Unity users. So it seems unlikely that Unity will remove it soon.

As for why Random.RandomRange specifically was made obsolete. Probably just for the clarity and consistency of naming. “Random.RandomRange” it’s somewhat redundant to call to repeat Random since the class name already implies that it is Random. “Random.Range” is also more consistent with other functions and properties like Random.value, Random.ColorHSV, Random.rotation, Random.insideUnitCircle.

yes and actually I did it even before asking this question… but I’m at the beginning… and I wanted to understand… in case it happens again… how can I get what I want even with the obsolete code… in terms of programming is there still a problem? and if so… why?

perfect!!! i love you ^^ ^^
tnk soo much to all