- Home /
I get error code CS0116 and I can't find the solution. Can you help me?
using UnityEngine;
using System.Collections;
public class PlayerControll : MonoBehaviour {
public float speed;
// Use this for initialization
void Start (){
count=0;
CountText();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
Vector3 movement = new Vector3(moveHorizontal,0.0f,moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
}
}
private int count;
public GUIText countText;
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == item)
{other.gameObject.SetActive(false);
count=count+1;
CountText();}
}
void CountText(){
countText.text="Count: " + count.ToString();
}
CS0116 "A namespace can only contain type and namespace declarations"
Answer by Nwhis · May 31, 2015 at 08:52 PM
The problem seems to be that you have other.gameObject.tag == item
instead of other.gameObject.tag == "item"
. Try adding the quotes. Also, not sure if ToString() works like that, on line 38.
I added the quotes to item, now it still displays the error. I am not sure about the codes, I used a unity tutorial and pretty much copy pasted the codes where they said I should.
Answer by revolute · Jun 01, 2015 at 08:07 AM
The problem here is that you have closed the class bracket.
Under fixedupdate, you have 2 closing brackets, meaning that any other code below it is considered as definition for other class but they do not match.
Simply remove one bracket and you are set.
Your answer
Follow this Question
Related Questions
A namespace can only contain types and namespace declarations 2 Answers
Errors in Unity2D 0 Answers
CommandInvokationFailure: Unable to install APK to device 6 Answers
Having difficulty with semicolons. 2 Answers
Google Ads Integration problems 1 Answer