Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Noobie1235 · May 31, 2015 at 08:19 PM · error

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();
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Noobie1235 · Jun 01, 2015 at 07:56 AM 0
Share

CS0116 "A namespace can only contain type and namespace declarations"

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · May 31, 2015 at 08:19 PM

I find the solution when I perform a search.

http://unity3d.com/search?refinement=answers&gq=CS0116

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Noobie1235 · Jun 01, 2015 at 08:02 AM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Noobie1235 · Jun 01, 2015 at 08:17 AM 0
Share

Thanks! It really helped.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges