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 captainvera · Apr 14, 2013 at 06:06 PM · javascriptsendmessagemelee

Can't put Sendmessage to work.

hey guys,

I have been trying to make a melee system where a sphereoverlap will tell me if there is any target in range, and if he is in range I'll test the distance as the sphereoverlap is not 100% accurate and if the distance checks out I'll send a message to the enemy to run the "DamageDeal" function, but for some reason it doesn't identify a receiver and never send the message.

Here's a bit of the code for melee that is supposed to send the message:

 var collisions : Collider[] = Physics.OverlapSphere(transform.position, range);
         for (var hit : Collider in collisions) 
         {
         
           
            if (hit && hit.tag == "enemy")
            { 
                 
             
             dist = Vector3.Distance(hit.transform.position, transform.position);
             
             Debug.Log(dist);
             Debug.Log("Step 2");
             if (dist <= range)
             {
             Debug.Log("Step 3");
             
             hit.gameObject.SendMessage("DamageDeal", dmg, SendMessageOptions.DontRequireReceiver);
             
             }
     
         }

and here's the code on the enemy:

 var currentHealth : int = 0;
 var maxHealth : int = 100;
 
 function Star() {
 
 currentHealth = maxHealth;
 }
 
 
 function Update () {
 
 if ( currentHealth <= 0)
     Destroy(gameObject); 
 }
 
 
 function DamageDeal (dmg : int)
 {
  Debug.Log("Step 4");
 currentHealth -= dmg; 
 
 }


What am i doing wrong?

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 whydoidoit · Apr 14, 2013 at 06:49 PM 0
Share

dmg is an int? You don't show it here. If it isnt then it wont work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by captainvera · Apr 14, 2013 at 07:02 PM

so, i was being retarded and put the tag on the wrong cube --' sorry all!

This is embarrassing..

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 whydoidoit · Apr 14, 2013 at 07:02 PM 0
Share

Happens :0)

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

12 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

Related Questions

Repeating Damage sendMessage 1 Answer

I have been watching his tutorial but nothing happens 0 Answers

Unity WebGL UnityInstance.SendMessage Error: SendMessage: object Object1 does not have receiver for function moveObject 1 Answer

character area attack problem 1 Answer

Problem sending array to unity player using SendMessage 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