void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == āscoreZoneā)
{
// register a score event
// play a sound
}
if (col.gameObject.tag == ādeadZoneā)
{ Rigidbody.simulated = false;(Rigidbody does not contain a definition for `simulated“)
//register a dead event
//play a sound
}
The error is exactly what it says. You donāt have any variable named ātapForceā defined in your script. Iām guessing your variable tapForence is the one you meant to use.
Rigidbody is a class in Unity, so my guess is itās getting confused and thinks you want the class and not the variable you defined. Itās bad practice to name variables after classes. Change the variable to name to rigidbody at the very least.
Thanks for the tip. I tried changing to lowercase r, but it didnt seem to help. When I changed it the error message said " the name ārigidbodyā does not exist in the current context" insteadā¦
That looks much better. I realize youāre new, but itās always helpful to post the exact error message and the line itās talking about (also the line that matches in your post, if it differs from the one in the actual message*).
You may have an extra closing brace ā}ā below the Update() method.
Thanks a lot! Removing the extra ā}ā fixed it.
Some new errors popped up as I created another script;
Row 6: āThe namespace āā already contains a definition for āGameManagerāā
Row 41 and 48: āThe name āOnPlayerDiedā does not exist in the current contextā
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
public delegate void GameDeligate();
public static event GameDeligate OnGameStarted;
public static event GameDeligate OnGameOverConfirmed;
public static GameManager Instance;
public GameObject startPage;
public GameObject gameOverPage;
public GameObject countdownPage;
public Text scoreText;
enum PageState
{
None,
Start,
GameOver,
Countdown
}
int score = 0;
bool gameOver = true;
public bool GameOver { get { return gameOver; } }
public int Score { get{return score;} }
void Awake()
{
Instance = this;
}
void OnEnable()
{
CountdownText.OnCountdownFinished += OnCountdownFinished;
TapController.OnPlayerDied += OnPlayerDied;
TapController.OnPlayerScored += OnPlayerScored;
}
void OnDisable()
{
CountdownText.OnCountdownFinished -= OnCountdownFinished;
TapController.OnPlayerDied -= OnPlayerDied;
TapController.OnPlayerScored -= OnPlayerScored;
}
void OnCountdownFinished()
{
SetPageState(PageState.None);
OnGameStarted(); //event sent TapController
score = 0;
gameOver = false;
}
void OnPlayedDied()
{
gameOver = true;
int savedScore = PlayerPrefs.GetInt("HighScore");
if (score> savedScore)
{
PlayerPrefs.SetInt("HihgScore", score);
}
SetPageState(PageState.GameOver);
}
void OnPlayerScored()
{
score++;
scoreText.text = score.ToString();
}
void SetPageState(PageState state)
{
switch (state)
{
case PageState.None:
startPage.SetActive(false);
gameOverPage.SetActive(false);
countdownPage.SetActive(false);
break;
case PageState.Start:
startPage.SetActive(true);
gameOverPage.SetActive(false);
countdownPage.SetActive(false);
break;
case PageState.GameOver:
startPage.SetActive(false);
gameOverPage.SetActive(true);
countdownPage.SetActive(false);
break;
case PageState.Countdown:
startPage.SetActive(false);
gameOverPage.SetActive(false);
countdownPage.SetActive(true);
break;
}
}
public void ComfirmGameOver()
{
//activated when replay button is hit
OnGameOverConfirmed(); //event sent TapController
scoreText.text = "0";
SetPageState(PageState.Start);
}
public void StartGame()
{
//activated when playbutton is hit
SetPageState(PageState.Countdown);
}
}
Thanks for your patience.
I dont really understand what you mean with the error on line 6. What do I have to do to fix it? I cant find another script on my computer with the same name if thats what you meant.
I am an absolute beginner and make some unnessecary errors, but hopefully I will learn from them.
Ya, itās no trouble. Just be sure to check the filename but also the script names (like when opened in your code editor).
You should always rename the file and the class name, if you do. Perhaps you renamed a file but forgot to do so in the class name?