Error in Unity code: Non-invocable member'GameManager.clearEf'cannot be used like a method

Asked 3 months ago, Updated 3 months ago, 6 views

I'm a beginner at Unity.
I am creating a tap game application based on the book, but I am worried because I am into the error.

I'm going to check the line, but I can't get the answer I want even if I search the error text.

Non-invocable member'GameManager.clearEf'cannot be used like a method.

I don't know why GameManager is pointing it out yet and I don't know how to read the error.

I would appreciate it if you could let me know if anyone knows.

Assets/Scripts/GameManager.cs(99,13): error CS1955: Non-invocable member'GameManager.clearEf'cannot be used like a method.
Assets/Scripts/GameManager.cs (129,54): error CS0103: The name 'lvup_efPrefab' does not exist in the current context
Assets/Scripts/GameManager.cs(139,55): error CS0103: The name 'lvup_efPrefab' does not exist in the current context

[GameManager.cs]

using System.Collections;
using System.Collections.General;
using UnityEngine;

using UnityEngine.UI;
using System;

public class GameManager:MonoBehavior {
// Constant definition
private constant MAX_ORB = 10; // maximum number of oven
private constant RESPAWN_TIME = 5; // Number of seconds an oven occurs
private constant MAX_LEVEL = 2; // maximum level

// Object reference
public GameObjectorbPrefab;// prefabricated of oven
publicGameObject lvupEf;//Effects at Level Up
public GameObject canvasGame; // Game Canvas
publicGameObject textScore; // Score text
public GameObject lvupImage;// Level Up Illustration
public GameObject clearEf;// Effect of clearing a game

// member variable
private int score = 0; // Current score
private int nextScore=10; // Score required before level-up

private int currentOrb = 0; // Current number of oven

private int levelRank = 0;// level rank

private DateTime lastDateTime; // The time the last oven was generated

private int [ ] nextScoreTable = new int [ ] {10,10,10 }; // Level Up Count

    // Start is called before the first frame update
    void Start() {
        // Initial oven generation
        currentOrb = 10;
        for(inti=0;i<currentOrb;i++){
            CreateOrb();
        }

        // Initial setting (In the start method, the image is set to the initial state.
        lastDateTime = DateTime.UtcNow;
        nextScore=nextScoreTable [levelRank];
        lvupImage.GetComponent<ObjectManager>().SetLvupPicture(levelRank);

        RefreshScoreText();
    }    

    // Update is called once per frame
    void Update() {
        if(currentOrb<MAX_ORB){
            TimeSpan timeSpan=DateTime.UtcNow-lastDateTime;

            if(timeSpan>=TimeSpan.FromSeconds(RESPAWN_TIME)){
                while(timeSpan>=TimeSpan.FromSeconds(RESPAWN_TIME)){
                    createNewOrb();
                    timeSpan-=TimeSpan.FromSeconds (RESPAWN_TIME);
                }
            }

        }
    }


    // Generate a new oven
    public void createNewOrb(){
        lastDateTime = DateTime.UtcNow;
        if(currentOrb>=MAX_ORB){
            return;
        }
        CreateOrb();
        currentOrb++;
    }

    // Ove generation
    public void CreateOrb(){
        GameObjectorb=(GameObject)Instantiate(orbPrefab);
        orb.transform.SetParent(canvasGame.transform, false);
        orb.transform.localPosition=new Vector3(
            UnityEngine.Random.Range (-300.0f, 300.0f),
            UnityEngine.Random.Range (-140.0f, -500.0f),
            0f);
    }

    // Obtaining Ove
    public void GetOrb(){
        score+=1;

        if(score>nextScore){
            score=nextScore;
        } 

        LevelUp();
        RefreshScoreText();

        // Game Clear Decision
        if((score==nextScore)&(levelRank==MAX_LEVEL)){
            clearEf();
        }

        currentOrb --;
    }

    // Score text update
    voidRefreshScoreText(){
        textScore.GetComponent<Text>().text=
        "Ove:"+score+"/"+nextScore;
    }

    // Image level management
    void LevelUp() {
        if(score>=nextScore){
            if(levelRank<MAX_LEVEL){
                levelRank++;
                score = 0;

                LevelUp();

                nextScore=nextScoreTable [levelRank];
                lvupImage.GetComponent<ObjectManager>().SetLvupPicture(levelRank);

            }
        }
    }

    // Performance at level up
    void LevelUpEffect() {
        GameObject lvupEf=(GameObject) Instantiate(lvup_efPrefab);

        lvupEf.transform.SetParent(canvasGame.transform, false);
        lvupEf.transform.SetSiblingIndex(2);

        Destroy(lvupEf, 0.5f);
    }

    // Performance when the level reaches the limit
    void ClearEffect() {
        GameObject clearEf=(GameObject) Instantiate(lvup_efPrefab);
        clearEf.transform.SetParent(canvasGame.transform, false);
    }
}

c# unity3d

2022-09-30 11:24

1 Answers

// Game Clear Decision
        if((score==nextScore)&(levelRank==MAX_LEVEL)){
            clearEf();
        }
// Game Clear Decision
        if((score==nextScore)&(levelRank==MAX_LEVEL)){
            clearEffect();
        }

Isn't that right?

Additional Edit
Code Change

// object reference
public GameObjectorbPrefab;// prefabricated of oven
// ↓ No need
// public GameObject lvupEf; // Effect at Level Up
public GameObject canvasGame; // Game Canvas
publicGameObject textScore; // Score text
public GameObject lvupImage;// Level Up Illustration
// ↓ No need
// public GameObject clearEf;// Effect of clearing the game
// ↓ Add
SerializeField
private GameObject lvup_efPrefab;
// Directed when level is up
    void LevelUpEffect() {
                         // ↓Change
        GameObject lvupEf = Instantiate(lvup_efPrefab) as GameObject;

        lvupEf.transform.SetParent(canvasGame.transform, false);
        lvupEf.transform.SetSiblingIndex(2);

        Destroy(lvupEf, 0.5f);
    }
//Performance when the level reaches the limit
    void ClearEffect() {
                          // ↓Change
        GameObject clearEf = Instantiate(lvup_efPrefab) as GameObject;
        clearEf.transform.SetParent(canvasGame.transform, false);
    }


2022-09-30 11:24

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.