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 /
avatar image
0
Question by Napter77 · Mar 12, 2017 at 10:30 PM · c#physicsrigidbodyragdollmethod

Cannot assign to 'Death' because its a method group

Hi I am new to coding and want to activate a rag-doll if the enemy's health value = 0, unfortunately in my code it says Cannot assign to Death because its a method group. If anyone can help my solve this issue I would greatly appreciate it. The code is down below( it is in the "void OnEnable()" section):

using UnityEngine; using System.Collections;

public class EnemyAI_Basic : MonoBehaviour { private EnemyAI_Basic enemyAI_Basic; Animator controller; float health; Animator anim; bool Alive = true; public bool Dead = false; int pointValue = 5; private Collider myCollider; private Rigidbody myRigidbody;

 CapsuleCollider capsuleCollider;


 void Start()
 {
     controller = GetComponentInParent<Animator>();
     health = 40;
     capsuleCollider = GetComponent<CapsuleCollider>();
     anim = GetComponent<Animator>();
 }

 void Update()
 {
     if (!Dead)
     {
         anim.SetTrigger("Alive");
     }
 }

 void Death()
 {
     Dead = true;
     Alive = false;
     capsuleCollider.isTrigger = true;
     anim.SetTrigger("Dead");
     Destroy(gameObject, 4f);
 }

 void OnEnable()
 {
     SetInitialReferences();
     enemyAI_Basic.Death += ActivateRagdoll;
 }


 void OnDisable()
 {
     enemyAI_Basic.Death -= ActivateRagdoll;
 }

 void SetInitialReferences()
 {
     enemyAI_Basic = transform.root.GetComponent<EnemyAI_Basic>();

     if (GetComponent<Collider>() != null)
     {
         myCollider = GetComponent<Collider>();
     }

     if (GetComponent<Rigidbody>() != null)
     {
         myRigidbody = GetComponent<Rigidbody>();
     }

 }

 void ActivateRagdoll()
 {
     if (myRigidbody != null)
     {
         myRigidbody.isKinematic = false;
         myRigidbody.useGravity = true;
     }

     if (myCollider != null)
     {
         myCollider.isTrigger = false;
         myCollider.enabled = true;
     }
 }

}

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mh_vitor · Mar 14, 2017 at 08:46 AM

Hello @Napter77,

This issue seems to be a syntax error. This syntax here:

 object.Property = value;

is used when you want to set that property with a valid value.

In the case at hand, you used

 object.Death = value;

but "Death" is a method. To send data to a method, you must pass it as an argument:

 object.Death(value);

although you can't do that since the Death() method takes no argument.

If what you want is that when the object is disabled it becomes a rag-doll and then dies, use:

void OnDisable() { SetInitialReferences(); ActivateRagdoll(); Death(); }

Though, if I recall correctly, a disabled object disappears from the screen, but you can just move the code to another method if you ever need.

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 IgorAherne · Mar 13, 2017 at 12:57 AM

Add the following line: public delegate void ZeroArgFunctionPointer(); near one of your variables.

Afterwards, also declare a variable ZeroArgFunctionPointer functionsToCall;

Where it says enemyAI_Basic.Death += ActivateRagdoll;, substitute it with functionsToCall += ActivateRagdoll;

do same for -= part, during OnDisable()

Finally, at the end of Death(), but before Destroy(), launch all the methods attached to our delegate (in your case just the ActivateRagdoll), in the order they were added. functionsToCall.Invoke()


Notice, if you do

 functionsToCall+=ActivateRagdoll; 
 functionsToCall+=ActivateRagdoll; 
 functionsToCall.Invoke();

this will invoke Activate Ragdoll twice, so be careful

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 Napter77 · Mar 13, 2017 at 11:44 AM 0
Share

Thanks I will check this out when I get home later today ;)

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

9 People are following this question.

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

Related Questions

How to change CC script to Rigidbody script 1 Answer

Get result (force & torque) of AddForceAtPosition? 2 Answers

RigidBody.MovePosition seems jerky in movement 0 Answers

Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 0 Answers

Handling colliders on hundreds of asteroids (not procedural asteroids) ...URGENT 3 Answers


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