- Home /
C# Parsing Error
Hi, I am getting the message Parsing Error but I don't know what is wrong since it is the only error statement in the console. Please help; below is my script code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText;
public GUIText winText;
private int count;
void Start ()
{
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce (movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
winText.text = "YOU WIN!";
}
}
void OnTriggerEnter (Collider other){
if (other.gameObject.tag == "NextLevel")
{
other.gameObject.CompareTag("Player");
Application.LoadLevel("Scene2");
}
}
Never$$anonymous$$d, I found out the problem; I was missing a } for the one in line 51. But now I have another problem. It says: Assets/Scripts/PlayerController.cs(51,14): error CS0111: A member `PlayerController.OnTriggerEnter(UnityEngine.Collider)' is already defined. Rename this member or use different parameter types
How am I not specific enough? And who says I didn't look up for the solution myself? You think I would ask here if I didn't look for an answer by myself in the Script Reference?
That's fine, but you need to post that in your question. Post the code you've tried, what you've done to try to solve the problem.
Frankly, there are users who just post here without looking anything up or trying anything and those questions are ignored by moderators.
I know there are users like those whom you described, but I am not one of them ;) I tried to somehow write an "if" statement after the
countText.text = "Count: " + count.ToString(); if (count >= 12) { winText.text = "YOU WIN!"; }
part of the script, but it didn't work out. And then I tried to look up for the SetActive function in the Reference, but it didn't help me...
Answer by perchik · Feb 26, 2014 at 06:10 PM
Your error message says it. There's two definitions of "OnTriggerEnter" at lines 29 and 51.
Can I write it somehow else to achieve the same thing, but not to double write OnTriggerEnter?
Please use the very small "add new comment" button for comments. Answers are meant to be solutions to the asked question.
I'm not entirely sure what you're trying to achieve, but I don't see why you can't just combine the functions:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
if (other.gameObject.tag == "NextLevel")
{
other.gameObject.CompareTag("Player");
Application.LoadLevel("Scene2");
}
}
Thank you very much perchik, you have solved my problem :) I would upvote you, but I don't have enough $$anonymous$$arma points :P
Since you guys keep deleting my questions, I'll ask here. How can I make a certain object (lets say it's name is Wall) deactivate if a text displays on the screen?
Your question is being deleted because it's not a specific, and you haven't posted anything about what you've tried or looked up. UA isn't for questions that are this vague.
Your answer

Follow this Question
Related Questions
Unexpected error 1 Answer
How do I fix this really wierd parsing error? 0 Answers
I am having a parsing error in a C# pause script, can anyone help? 1 Answer
Json parsing error Unity 5.6 0 Answers
Jukebox parsing error 2 Answers