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 Carbongrip · Nov 11, 2013 at 05:02 PM · c#targetsendmessagehealth

Why don't my send messages work?

Well as seen in title messages are not working… they just end up causing all the send messages to activate lol…

Heres a part of the weapons script...

if (angleForward < minAngle) { shieldHit = "Forward"; minAngle = angleForward; if(shieldHit == "Forward") { script.selectedTarget.; } else if(script.ForwardShields <= 0) { script.Shields = false;
} }

                        if (angleBack < minAngle)
                     {
                          shieldHit = "Back";
                          minAngle = angleBack;
                         if(shieldHit == "Back")
                         {
                             script.selectedTarget.SendMessage("ApplyShieldDamageAft", 700);
                         }
                         else if(script.AftShields <= 0)
                         {
                             script.Shields = false;    
                         }
                        }
 
                        if (angleRight < minAngle)
                     {
                          shieldHit = "Right";
                          minAngle = angleRight;
                         if(shieldHit == "Right")
                         {
                             //hit.transform.SendMessage("ApplyShieldDamageStarboard", 700, SendMessageOptions.DontRequireReceiver);
                         }
                         else if(script.StarboardShields <= 0)
                         {
                             script.Shields = false;    
                         }
                        }
 
                        if (angleLeft < minAngle)
                     {
                          shieldHit = "Left";
                          minAngle = angleLeft;
                         if(shieldHit == "Left")
                         {
                             //hit.transform.SendMessage("ApplyShieldDamagePort", 700, SendMessageOptions.DontRequireReceiver);
                         }
                         else if(script.PortShields <= 0)
                         {
                             script.Shields = false;    
                         }
                        }
 
                        if (angleTop < minAngle)
                     {
                          shieldHit = "Top";
                          minAngle = angleTop;
                         if(shieldHit == "Top")
                         {
                             //hit.transform.SendMessage("ApplyShieldDamageDorsal", 700, SendMessageOptions.DontRequireReceiver);
                         }
                         else if(script.DorsalShields <= 0)
                         {
                             script.Shields = false;    
                         }
                        }
 
                        if (angleBot < minAngle)
                     {
                          shieldHit = "Bottom";
                          minAngle = angleBot;
                         if(shieldHit == "Bottom")
                         {
                             //hit.transform.SendMessage("ApplyShieldDamageVentral", 700, SendMessageOptions.DontRequireReceiver);
                         }
                         else if(script.VentralShields <= 0)
                         {
                             script.Shields = false;    
                         }
                        }

Heres the stats script…

 using UnityEngine;
 using System.Collections;
 
 public class --------------- : MonoBehaviour
 {
     public string ------------ = "---------------";
     public float Shiphull = 32500;
     public float ForwardShields = 4350;//front
     public float AftShields = 4350;//back
     public float PortShields = 4350;//left
     public float StarboardShields = 4350;//right
     public float DorsalShields = 4350;//top
     public float VentralShields = 4350;//bottom
     public bool Shields = true;
     
     void ApplyShieldDamageForward(int ShieldDamageForward)
     {
         ForwardShields -= ShieldDamageForward;
     }
     
     void ApplyShieldDamageAft(int ShieldDamageAft)
     {
         AftShields -= ShieldDamageAft;
     }
     
     void ApplyShieldDamagePort(int ShieldDamagePort)
     {
         PortShields -= ShieldDamagePort;
     }
     
     void ApplyShieldDamageStarboard(int ShieldDamageStarboard)
     {
         StarboardShields -= ShieldDamageStarboard;
     }
     
     void ApplyShieldDamageDorsal(int ShieldDamageDorsal)
     {
         DorsalShields -= ShieldDamageDorsal;
     }
     
     void ApplyShieldDamageVentral(int ShieldDamageVentral)
     {
         VentralShields -= ShieldDamageVentral;
     }
     
     void ApplyDamage(int damage)
     {
         Shiphull -= damage;
     }
     
     void Update ()
     {
         if(Shiphull <= 0)
         {
             Destroy(gameObject,5);
         }
     }
 }

any ideas?

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
1
Best Answer

Answer by Tomer-Barkan · Nov 12, 2013 at 07:08 AM

You're not using the shield hit calculation script correctly. You have to do it exactly like I showed you here.

Within the if (angle < minAngle), you don't apply the damage yet, because there can be another angle later that is smaller. So first you run all the ifs, only after you run all the ifs can you tell which one is the minimal. After that, you can apply the damage.

Within the if, you can decide which message to send, using shieldHit = "ApplyShieldDamageAft";, etc.

Then only after you checked ALL the angles, you can actually apply damage:

 script.selectedTarget.SendMessage(shieldHit);


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 Carbongrip · Nov 12, 2013 at 10:33 PM 0
Share

Thank you! Oh and can I use you targeting angles in someway that makes my beam weapon fire in a certain arc? Like say a 250 targeting arc? anyways see this thread if you can :)

avatar image
0

Answer by Sundar · Nov 11, 2013 at 05:14 PM

Make all your methods public like

public void ApplyShieldDamageAft(...)

Comment
Add comment · Show 2 · 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 kmeboe · Nov 11, 2013 at 06:17 PM 0
Share

You shouldn't need "public" with Send$$anonymous$$essage methods.

So you're saying that when you just call

 script.selectedTarget.Send$$anonymous$$essage("ApplyShieldDamageAft", 700);

every one of the methods inside Galaxy_Pref() gets called? I would suggest adding Debug.Log() statements inside each method, and also one when you call Send$$anonymous$$essage. This might help you see what's going on.

avatar image kmeboe · Nov 12, 2013 at 04:10 AM 0
Share

Did you see my comment above? It's hard for me to solve this directly for you, because I haven't seen the problems with Send$$anonymous$$essage() that you describe. Have you tried following the steps I gave above? What was the result?

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

18 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

Related Questions

[C#]Health Regeneration and Delay 3 Answers

how to make one script change a variable in another scipt 2 Answers

If health = 0, show a GUI.button C# 2 Answers

Targeting problem 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