- Home /
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?
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);
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 :)
Answer by Sundar · Nov 11, 2013 at 05:14 PM
Make all your methods public like
public void ApplyShieldDamageAft(...)
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.
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
Follow this Question
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