The question is answered, right answer was accepted
[SOLVED] Stop counting score code error!
Hello! I am working at my video game, a simple 2D game, a kind of side scroller. Bellow you have some pics with game. The problem is with a code. I try to make a code that will stop the counting of score when the character hits an obstacle. I have used a collide function but from 3 days it gives me two errors. Bellow I give you the code and some pics with errors. I really need help and i will appreciate your help. Thanks!
The game
The code with funtion. Funtion is last.
using UnityEngine;
using System.Collections;
public class CharacterMovment : MonoBehaviour {
public float speed = 3.5f;
public UIManager ui;
// Use this for initialization
void Start () {
//ui = GetComponent<UIManager> ();
}
// Update is called once per frame
void Update () {
/*if (Input.GetKey (KeyCode.D))
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
if (Input.GetKey (KeyCode.A))
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);*/
if (Input.GetKey (KeyCode.W))
transform.position += new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
if (Input.GetKey (KeyCode.S))
transform.position -= new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
}
void OnCollisionEnter(Collision col)
{
if (col.GameObject.tag == "Obstacle")
{ ui.GameOverActivated; }
}
}
The erros
And this is UIManager. I dont konw, but maybe it will help you.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UIManager : MonoBehaviour {
public Text ScoreText;
int score;
bool GameOver;
// Use this for initialization
void Start () {
score = 0;
InvokeRepeating("ScoreUpdate", 0.3f, 0.01f);
GameOver = false;
}
// Update is called once per frame
void Update () {
ScoreText.text = "SCORE " + score;
}
void ScoreUpdate ()
{
if (GameOver == false)
{ score += 1; }
}
public void GameOverActivated ()
{
GameOver = true;
}
public void Play ()
{
Application.LoadLevel("PrincipalLevel");
}
public void Pause ()
{
That is it! I have search on google the problems, but i did not find something clear that cand help me. If is someone who can help me, I will appreciate. Thanks again!
Answer by Linus · Oct 11, 2015 at 01:25 PM
Use gameObject not GameObject :)
Gave you some points as clearly you do not need to be in moderation que. Prime example of how to ask for help.
Oh God what stupidness :)))) Thank you very much. But the second error still appear. I think that it is also a little thing :) And thanks for the rep points also. I have seen something about moderation or something like "the question need to be reviwed by a moderator" but I didn't gave no importance. I dont know how happend.
SOLVED! Thanks again for help! The second, was also a stupidness :))
So. First error was solved by @Linus and the scond error i have solved it. I just changed some things.
Ins$$anonymous$$d of
ui.GameOverActivated;
I have putted
UI$$anonymous$$anager.GameOver = true;
And it is working.
Glad it got solved. Did not look more into it when I saw the first error. Often they stack up when there is one error.
I once spent days before I saw that i had used OnEnabled ins$$anonymous$$d of OnEnable.
Yes new users have their question sent to moderation que. They also cant post comments, so they end up posting answers ins$$anonymous$$d of comments.
Please mark the question as answered.
Follow this Question
Related Questions
Count objects inside a dynamic area? 0 Answers
Soccer game, more realistic net 1 Answer
How to make a Compact-Disc shaped collider object with an empty hole inside? (2D, not a 3D torus) 0 Answers
How do add scenes on the Countdown Timer 0 Answers
One script with multiple Gameobject only one Works 0 Answers