Hello! I cannot get my script to work after Lecture 108, Introducing Encapsulation of the Complete C# Unity Game Developer 3D - Archived Course.
My problem is in this error:
Assets\Scripts\Enemy.cs(28,20): error CS0122: ‘ScoreBoard.ScoreHit(int)’ is inaccessible due to its protection level
Here is my Enemy script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
[SerializeField] GameObject deathFX;
[SerializeField] Transform parent;
[SerializeField] int scorePerHit = 12;
ScoreBoard scoreBoard;
// Start is called before the first frame update
void Start()
{
scoreBoard = FindObjectOfType<ScoreBoard>();
}
// Update is called once per frame
void Update()
{
}
void OnParticleCollision(GameObject other)
{
scoreBoard.ScoreHit(scorePerHit);
GameObject fx = Instantiate(deathFX, transform.position, Quaternion.identity);
fx.transform.parent = parent;
Destroy(gameObject);
}
}
And here is my ScoreBoard script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreBoard : MonoBehaviour
{
int score = 0;
Text scoreText;
// Start is called before the first frame update
void Start()
{
scoreText = GetComponent<Text>();
scoreText.text = score.ToString();
}
private void ScoreHit(int scoreIncrease)
{
score = score + scoreIncrease;
scoreText.text = score.ToString();
}
}
I think the problem may have to do with the ScoreBoard in the Enemy Script is not referencing ScoreBoard.cs script. I don’t really understand the problem, but I think this is what is wrong, but Unity says
'ScoreBoard.ScoreHit(int)’ is inaccessible due to its protection level
Help would be greatly appreciated!!
Thank you!