Thought I understood, but I guess not

So I am a little confused. I tried to create a new variable as a cached reference in my Block script, using GameStatus gameStatus; but when I add the initializtion under the start function, I am getting an error that reads, " cannot convert method group ‘FindObjectType’ to non-delegate type ‘GameStatus’. Did you intend to invoke the method?

I am posting my script for GameStatus, and Block… I dont understand what is not working. Especially since it is working for the Level reference… can someone please take a look and explain why this isnt right…

public class Block : MonoBehaviour
{
[SerializeField] AudioClip blockBreak;

//cached reference
Level level;
GameStatus gameStatus;

private void Start()
{
    level = FindObjectOfType<Level>();
    level.CountBreakableBlocks();
    gameStatus = FindObjectOfType<GameStatus>;
}

private void OnCollisionEnter2D(Collision2D collision)
{
    DestroyBlock();
}

private void DestroyBlock()
{
    
    AudioSource.PlayClipAtPoint(blockBreak, Camera.main.transform.position);
    gameStatus.AddToScore();
    Destroy(gameObject);
    level.BlockDestroyed();
    
}

}

public class GameStatus : MonoBehaviour
{

// Config Params
[Range(0.1f, 10f)] [SerializeField] float gameSpeed = 1.0f;
[SerializeField] int pointsPerBlock = 42;

// state variables
[SerializeField] int currentScore = 0;

//cached references
Level level;

// Start is called before the first frame update

// Update is called once per frame
void Update()
{
    Time.timeScale = gameSpeed;
}

public void AddToScore()
{
    currentScore = currentScore + pointsPerBlock;
    //could be written as "currentScore += pointsPerBlock;"
}

}

Looks like you’re missing the method call/parenthesis from
FindObjectOfType<GameStatus>;
which is why the error says “Did you intend to invoke the method?”

1 Like

:man_facepalming: Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms