Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Mar 25, 2016 at 11:35 PM by arksenu for the following reason:

I figured out the problem.

avatar image
0
Question by arksenu · Mar 23, 2016 at 01:02 PM · scorespace shootergamecontroller

Space Shooter No Definition

I'm writing the tutorial space shooter, and I am attempting to use the method AddScore from the GameController class.

Here is the method:

 public void AddScore(int newScoreValue) {
         score += newScoreValue;
         UpdateScore ();
     }

Then, in the DestroyByContact class i am trying to access it like this:

 public GameController gameController;
 public int scoreValue;
 
 gameController.AddScore (scoreValue);


In the console this error reads:

 Assets/Scripts/DestroyByContact.cs(23,32): error CS1061: Type `GameController' does not contain a definition for `AddScore' and no extension method `AddScore' of type `GameController' could be found (are you missing a using directive or an assembly reference?)
 

Anyone know why this might be? thanks

Comment
Add comment · Show 3
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 Hellium · Mar 23, 2016 at 08:26 AM 0
Share

gameController.AddScore (scoreValue); is not in a function ? If so, obviously, put it in a function ....

avatar image arksenu · Mar 23, 2016 at 10:54 PM 0
Share

It is in a functon, i just didn't show the whole thing.

avatar image Hellium · Mar 24, 2016 at 07:45 AM 0
Share

Have you imported the GameController namespace as suggested ?

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Ali-hatem · Mar 24, 2016 at 10:44 AM

 public class DestroyByContact : MonoBehaviour {
     GameController gameController;
     GameObject obj;
     public int scoreValue;
     void Start(){
 obj = GameObject.Find ("the name of the object that GameController script attached to");
         if (obj != null) {
             gameController= obj.GetComponent<GameController > ();
             gameController.AddScore (scoreValue);
         }
         else {
             print ("no object with the given name found did you gave the exact name");
         }
     }
 }
Comment
Add comment · Show 4 · 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 arksenu · Mar 25, 2016 at 12:20 AM 0
Share

But it is attached to multiple objects?

avatar image Ali-hatem arksenu · Mar 25, 2016 at 10:20 AM 0
Share

i can give you other solution by cheeking tag ins$$anonymous$$d of name but i don't know what are you trying to do what will happen if score variable was different in each object what scoreValue variable will be so if it not necessary put the score & the function you try to call in one object . but if you have other plain tell me what's going on!

avatar image arksenu Ali-hatem · Mar 25, 2016 at 02:14 PM 0
Share

Well, the score value is that same, but I don't want collisions between obstacles cause an increase in the score, only when the player shoots and hits.

Show more comments

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity keeps freezing every time I enter playmode!!! Help!! 1 Answer

Mouse Look / Cursor 1 Answer

How to remove floating 0 Answers

open door to next level, after 10000 points were added to your score (solved) 2 Answers

Problem with a score script 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