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 Dec 28, 2014 at 02:45 PM by T-D-M-3 for the following reason:

I found the problem within My health Script

avatar image
0
Question by T-D-M-3 · Dec 28, 2014 at 02:24 PM · javascriptdamagesendmessagemelee

Repeating Damage sendMessage

So i have this Melee Damage Script that when it collides with an object it sends a message to deal 5 damage. The Problem i have is that it collides and sends 5 damage, but then continues to do the 5 damage every frame. Is there Any way to fix this?

here are the scripts for the melee damage and the damage receiver, Both Javascript

Damage Script:

 var Damage : int = 5;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter(hit:Collider){
 
 
 hit.transform.SendMessage("Damage",Damage, SendMessageOptions.DontRequireReceiver);
 
 
 Debug.LogError("Impact");
 
 }
 
 
 

Damage Reciver:

 var HealthScript : AiHealth;
 var HitEffect : Transform;
 var Point : Transform;
 
 function Damage(Damage:int){
 
 HealthScript.Health -= Damage;
 
 var GotHit : Transform = Instantiate(HitEffect, Point.position, 
                                                Point.rotation);
                                                
 }
 
 function Start () {
 
 }
 
 function Update () {
 
 }

   
 
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Maurice_B · Dec 28, 2014 at 07:53 PM

you cannot send extra data through sendmessage. this may help:

 var Damage : int = 5;
 var receiver : reciverscriptnamehere;//the name of your reciever.js. 
  function Start () {
  
  }
  
  function Update () {
  
  }
  
  function OnTriggerEnter(hit:Collider){
  
  receiver = hit.gameObject.GetComponent(recieverscriptnamehere);//assign the reciever a script.
  //hit.transform.SendMessage("Damage",Damage, SendMessageOptions.DontRequireReceiver); not working;
  receiver.Damage(Damage);
  
  Debug.LogError("Impact");
  
  }

hope that works for you.(code may need correcting capitals I don't have uity on right now.)

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

Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't put Sendmessage to work. 1 Answer

Send Message Not sending 2 Answers

on collision damage 1 Answer

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

Possible Fall Damage OnCollisionEnter Won't Work! 0 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