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!