Access a dynamic changing boolean from another script but return random value
Hello everyone,
i'm trying to monitor a boolean value "isMessageRecieved" from another script (at same gameobject) in the FixedUpdated() to do something. I'm pretty sure that the first script where the boolean "isMessageRecieved" originally located is workiing fine. Following script is part of my code of it.
// New thread
// If the message is recieved outside from unity, isMessageReceived set true
protected override void ReceiveMessage(MessageTypes.Geometry.Twist message)
{
-------Do Something ------
isMessageReceived = true;
}
private void FixedUpdate()
{
if (isMessageReceived)
ProcessMessage();
}
private void ProcessMessage()
{
-------Do Something ------
isMessageReceived = false;
}
However, when it comes to second script which monitor "isMessageRecievd", the value is completely chaos. It return true/false value in a random order, which i can't figure it out at all. please help me!
void FixedUpdate()
{
GetVelocity();
----------------Do Sometihng------------------
}
private void GetVelocity()
{
// Access the boolean with getcompenent<>().
// I also tried setting boolean to public static but don't work neither
if(gameObject.GetComponent<TwistSubscriber>().isMessageReceived)
{
------- Do Something--------
}
else
{
------- Do Something--------
}
}
Your answer
Follow this Question
Related Questions
error CS0116: A namespace can only contain types and namespace declarations 0 Answers
Score, FixedUpdate and Update 0 Answers
Physics inconsistent even when using FixedUpdate() or Time.DeltaTime() 0 Answers
Why doesn't the collider work? 1 Answer
how to keep an animation condition after Application.loadLevel 0 Answers