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 /
This question was closed Jul 19, 2013 at 01:13 PM by MadJohny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MadJohny · Jul 19, 2013 at 09:54 AM · c#errorerror-handling

Expression denotes a `method group', where a `variable', `value' or `type' was expected

Hi, so I started working on the AI attack function, I am having some problems tho, in the last line of this part of my script:

 void Attack () {
         RaycastHit hit;
         if (Physics.Raycast(transform.position, transform.forward, out hit)){
             if(hit.distance <= minimumDistance && hit.transform.tag == "Player"){
                 hit.collider.gameObject.GetComponent<Player>.health -= damage;

in the last line I am getting this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(31,57): error CS0119: Expression denotes a method group', where a variable', value' or type' was expected, it's not the first time I have this error, I had it in one line that is above:

         GameObject tempClosestEnemy = gameObject.GetComponent<EnemyScript>().closestPlayer;
         if(Vector3.Distance(transform.position, tempClosestEnemy.transform.position) <= minimumDistance){

but I fixed it creating the temporary variable to store the value, it worked (btw is the var type supposed to be GameObject?) so in the line that I am having the error I also tried making a temporary variable (GameObject type) to store it, but I was getting this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(31,87): error CS0119: Expression denotes a method group', where a variable', value' or type' was expected in the temporary variable line, and this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(32,33): error CS0019: Operator -=' cannot be applied to operands of type UnityEngine.GameObject' and `int' in the second line:

             GameObject tempPlayerHealth = hit.collider.gameObject.GetComponent<Player>.health;
             tempPlayerHealth -= damage;

help me please! and thanks in advance

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 Graham-Dunnett ♦♦ · Jul 19, 2013 at 11:02 AM 0
Share

Does a collider have a gameObject? It's not listed at http://docs.unity3d.com/Documentation/ScriptReference/Collider.html.

1 Reply

  • Sort: 
avatar image
6
Best Answer

Answer by Graham-Dunnett · Jul 19, 2013 at 11:02 AM

The documentation for GetComponent shows that it is a function and so need parentheses.

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 MadJohny · Jul 19, 2013 at 11:32 AM 0
Share

how did I miss that o.O, I already knew that bt totally escaped me-.- thanks anyway!

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

InvalidCastException: Cannot cast from source type to destination type. 1 Answer

Error, I have no idea why :( 2 Answers

Distribute terrain in zones 3 Answers

error CS0118: `New_Career.Fame' is a `field' but a `type' was expected 1 Answer

Multiple Cars not working 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