private void Update()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                EventsCheck();
                string s = "Deactivated";
                if (fullyDeployed && resourceOn)
                {
                    s = "Searching...";
                    Vessel           target    = FlightGlobals.fetch.VesselTarget as Vessel;
                    FlightCoMTracker targetObj = FlightGlobals.fetch.VesselTarget as FlightCoMTracker;

                    if (target != null)
                    {
                        targetModule = target.FindPartModulesImplementing <DMAsteroidScanner>().FirstOrDefault();
                    }
                    else if (targetObj != null)
                    {
                        var targets = targetObj.GetOrbitDriver().vessel.FindPartModulesImplementing <DMAsteroidScanner>();
                        if (targets.Count > 0)
                        {
                            if (targets.Count > 1)
                            {
                                foreach (DMAsteroidScanner t in targets)
                                {
                                    if (t == this)
                                    {
                                        continue;
                                    }

                                    float d = (t.part.transform.position - dishBase.position).sqrMagnitude;
                                    if (d > 4f)
                                    {
                                        targetModule = t;
                                        break;
                                    }
                                    else
                                    {
                                        targetModule    = null;
                                        targetDistance  = 0f;
                                        receiverInRange = asteroidInSight = false;
                                    }
                                }
                            }
                            else if (targets[0] != this)
                            {
                                targetModule = targets[0];
                            }
                        }
                        else
                        {
                            targetModule    = null;
                            targetDistance  = 0f;
                            receiverInRange = asteroidInSight = false;
                        }
                    }
                    else
                    {
                        var targets = vessel.FindPartModulesImplementing <DMAsteroidScanner>();
                        if (targets.Count > 1)
                        {
                            foreach (DMAsteroidScanner t in targets)
                            {
                                if (t == this)
                                {
                                    continue;
                                }

                                float d = (t.part.transform.position - dishBase.position).sqrMagnitude;
                                if (d > 4f)
                                {
                                    targetModule = t;
                                    break;
                                }
                                else
                                {
                                    targetDistance  = 0f;
                                    targetModule    = null;
                                    receiverInRange = asteroidInSight = false;
                                }
                            }
                        }
                        else
                        {
                            targetDistance  = 0f;
                            targetModule    = null;
                            receiverInRange = asteroidInSight = false;
                        }
                    }

                    if (targetModule != null)
                    {
                        s = "Receiver Located";
                        targetDistance = (targetModule.part.transform.position - dishBase.position).sqrMagnitude;
                        if (targetDistance < (2000 * 2000) && targetDistance > 4)
                        {
                            s = "Receiver In Range";
                            receiverInRange = true;
                            if (simpleRayHit())
                            {
                                s = "Experiment Ready";
                                asteroidInSight = true;
                            }
                            else
                            {
                                asteroidInSight = false;
                            }
                        }
                        else
                        {
                            receiverInRange = asteroidInSight = false;
                            targetDistance  = 0f;
                        }
                    }
                    else
                    {
                        receiverInRange = asteroidInSight = false;
                        targetDistance  = 0f;
                    }

                    if (receiverInRange && targetModule != null)
                    {
                        lookAtTarget();
                    }
                    else
                    {
                        searchForTarget();
                    }
                    rotating = true;
                }
                else if (fullyDeployed && !resourceOn && resourceCost > 0f)
                {
                    s = "No Power";
                    targetDistance  = 0f;
                    targetModule    = null;
                    receiverInRange = asteroidInSight = false;
                }
                else if (rotating)
                {
                    spinDownDish();
                    targetDistance  = 0f;
                    targetModule    = null;
                    receiverInRange = asteroidInSight = false;
                }
                else
                {
                    targetDistance  = 0f;
                    targetModule    = null;
                    receiverInRange = asteroidInSight = false;
                }

                lightSwitch(receiverInRange && asteroidInSight, !IsDeployed);

                status = s;
            }
        }
        private void Update()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                EventsCheck();
                string s = "Deactivated";
                if (fullyDeployed && resourceOn)
                {
                    s = "Searching...";
                    Vessel target = FlightGlobals.fetch.VesselTarget as Vessel;
                    FlightCoMTracker targetObj = FlightGlobals.fetch.VesselTarget as FlightCoMTracker;

                    if (target != null)
                    {
                        targetModule = target.FindPartModulesImplementing<DMAsteroidScanner>().FirstOrDefault();
                    }
                    else if (targetObj != null)
                    {
                        var targets = targetObj.GetOrbitDriver().vessel.FindPartModulesImplementing<DMAsteroidScanner>();
                        if (targets.Count > 0)
                        {
                            if (targets.Count > 1)
                            {
                                foreach (DMAsteroidScanner t in targets)
                                {
                                    if (t == this)
                                        continue;

                                    float d = (t.part.transform.position - dishBase.position).magnitude;
                                    if (d > 2f)
                                    {
                                        targetModule = t;
                                        break;
                                    }
                                    else
                                    {
                                        targetModule = null;
                                        targetDistance = 0f;
                                        receiverInRange = asteroidInSight = false;
                                    }
                                }
                            }
                            else if (targets[0] != this)
                                targetModule = targets[0];
                        }
                        else
                        {
                            targetModule = null;
                            targetDistance = 0f;
                            receiverInRange = asteroidInSight = false;
                        }
                    }
                    else
                    {
                        var targets = vessel.FindPartModulesImplementing<DMAsteroidScanner>();
                        if (targets.Count > 1)
                        {
                            foreach (DMAsteroidScanner t in targets)
                            {
                                if (t == this)
                                    continue;

                                float d = (t.part.transform.position - dishBase.position).magnitude;
                                if (d > 2f)
                                {
                                    targetModule = t;
                                    break;
                                }
                                else
                                {
                                    targetDistance = 0f;
                                    targetModule = null;
                                    receiverInRange = asteroidInSight = false;
                                }
                            }
                        }
                        else
                        {
                            targetDistance = 0f;
                            targetModule = null;
                            receiverInRange = asteroidInSight = false;
                        }
                    }

                    if (targetModule != null)
                    {
                        s = "Receiver Located";
                        targetDistance = (targetModule.part.transform.position - dishBase.position).magnitude;
                        if (targetDistance < 2000 && targetDistance > 2)
                        {
                            s = "Receiver In Range";
                            receiverInRange = true;
                            if (simpleRayHit())
                            {
                                s = "Experiment Ready";
                                asteroidInSight = true;
                            }
                            else
                                asteroidInSight = false;
                        }
                        else
                        {
                            receiverInRange = asteroidInSight = false;
                            targetDistance = 0f;
                        }
                    }
                    else
                    {
                        receiverInRange = asteroidInSight = false;
                        targetDistance = 0f;
                    }

                    if (receiverInRange && targetModule != null)
                        lookAtTarget();
                    else
                        searchForTarget();
                    rotating = true;
                }
                else if (fullyDeployed && !resourceOn && resourceCost > 0f)
                {
                    s = "No Power";
                    targetDistance = 0f;
                    targetModule = null;
                    receiverInRange = asteroidInSight = false;
                }
                else if (rotating)
                {
                    spinDownDish();
                    targetDistance = 0f;
                    targetModule = null;
                    receiverInRange = asteroidInSight = false;
                }
                else
                {
                    targetDistance = 0f;
                    targetModule = null;
                    receiverInRange = asteroidInSight = false;
                }

                lightSwitch(receiverInRange && asteroidInSight, !IsDeployed);

                status = s;
            }
        }