O
O
Oleg_Lin2020-07-03 15:20:45
C++ / C#
Oleg_Lin, 2020-07-03 15:20:45

Explain why the following line causes an error in Unity(C#)?

Explain plz. why does the following line cause an error in Unity:

scene_controll = gameObject.Find("Big_enemy").GetComponent<SceneController>();

Here is the error:
Assets\ReactiveTarget.cs(21,26): error CS0176: Member 'GameObject.Find(string)' cannot be accessed with an instance reference;

qualify it with a type name instead
  • All necessary components and methods with the public modifier
  • The "scene_controll" object is declared at the beginning of the class:
    SceneController scene_controll;
  • An object named "Big_enemy" exists in the scene
  • I also tried to write it like this:
    scene_controll = gameObject.Find("Big_enemy").GetComponent("SceneController");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-07-03
@Oleg_Lin

scene_controll = GameObject.Find("Big_enemy").GetComponent<SceneController>();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question