#Need help with error CS0103

1 messages · Page 1 of 1 (latest)

zinc quiver
#
using System.Collections.Generic;
using UnityEngine;

public class ReactiveTargets : MonoBehaviour{

    [SerializeField] LevelController gameController;

    [SerializeField] UIController ui;

    void Start()
    {
        gameController = FindAnyObjectByType<LevelController>();
        ui = FindAnyObjectByType<UIController>();
    }


    public void ReactToHit()
    {
        WanderingAI Behavior = GetComponent<WanderingAI>();
        if (Behavior != null)
        {
            Behavior.SetAliveStatus(false);
        }
        int newScore = gameController.GetScore() + 1;
        gameController.SetScore(newScore);
        ui.UpdateScoreText(newScore.ToString());
        StartCoroutine(Die());
    }

    IEnumerator Die()
    {
        transform.Rotate(-75, 0, 0);
        
        yield return new WaitForSeconds(1.5f);

        Destroy(this.gameObject);

    }

}
somber onyx
#

you should post the error message so we have an idea of what the error/problem is . . .

#

no one knows what the error numbers are . . .

zinc quiver
#

Right, sorry, I posted this a bit prematurely

#

Should I close this thread and start a new one?

somber onyx
#

why? what for? it wouldn't be any different than this one. just post the error message . . .

#

and explain what the code is suppose to do . . .

zinc quiver
#

Okay, the error I got was CS0103: The name 'FindAnyObjectByType' does not exist in the current context. I'm following a game programming class and I've been following it, copying most of what the professor does.

#

As for what it does, from what I can understand, the code is to have an enemy object react to getting hit from a Raycast, a basic wandering AI, and update a score number on a user interface (which is what we're focusing on).

somber onyx
#

what unity version are you using?

zinc quiver
#

Before adding the Start method, it was giving a NullReferenceException Error, but after adding the Start method referencing the "Find Any Object..." function, it worked for the professor, but when I did it, it said the error message I'm now struggling with

zinc quiver
#

"2020.3.43f1" is the version I'm using

somber onyx
#

what version is the tutorial using?

zinc quiver
#

Second edition of Unity In Action by Joseph Hocking

#

That is what the professor's using to do the assignment

somber onyx
#

?

zinc quiver
#

Basically this text book

#

Sorry if this isn't much info to work with

somber onyx
#

you need to see what version of unity they're using. it should be in the book. since it's published in 2018 it's definitely not a new(er) version, which means, it wouldn't have FindAnyObjectByType in their code, so i'm not sure where you got that from . . .

#

you're using a method that does not exist for that type . . .

zinc quiver
#

Looking at the version of what my professor has, it's actually a slightly later version of unity (2020.3.47f), so I'm not sure if version type has much of a say

#

If you'd like, I'm able to send the video I'm watching in order to do this assignment

#

The professor gets to the part I'm struggling on around the 49:00 minute mark

zinc quiver
#

An interesting thing to note is the fact that when I type out FindAnyObjectByType, nothing interesting happens, but on my professor's screen, it shows a bunch of other methods that basically show as suggestions, one of the being FindAnyObjectOfType

#

Not the same type, sure, but it's something worth pointing out I think

zinc quiver
#

Okay, so it seems I fixed it, so instead of having it as FindAnyObjectByType, I put it as FindObjectOfType and I have gotten no errors