// Use this for initialization // start and update will call themselves through unity
    void Start()
    {
        playerBehaviour = GameObject.Find("Player").GetComponent <PlayerBehaviour>();
        stateController = GameObject.Find("State Controller").GetComponent <StateController>();
        scoreCollision  = GameObject.Find("Score Collider").GetComponent <ScoreCollision>();
        id = GameObject.Find("Incoming Object Detection").GetComponent <IncomingDetection>();

        slideDeathCounter = StoredData.slideDeath;
        jumpDeathCounter  = StoredData.jumpDeath;
        action.reward3    = Mathf.Max(StoredData.reward2, StoredData.reward1) + 1;
    }
 void Start()
 {
     //Debug.Log("Previous Score was: " + StoredData.score); // Output stored previous score for testing
     stateController = stateControllerObject.GetComponent <StateController>();
     id = GameObject.Find("Incoming Object Detection").GetComponent <IncomingDetection>();
 }
        public override void SimulateFixedUpdateAlways()
        {
            ++FUcounter;
            if (HitPoints <= 0)
            {
                if (FUcounter % 50 == 0)
                {
                    GameObject boom = (GameObject)Instantiate(PrefabMaster.BlockPrefabs[54].gameObject, this.transform.position, this.transform.rotation);
                    DestroyImmediate(boom.GetComponent <Renderer>());
                    DestroyImmediate(boom.GetComponent <Collider>());
                    boom.GetComponent <ControllableBomb>().power       = 0;
                    boom.GetComponent <ControllableBomb>().upPower     = 0;
                    boom.GetComponent <ControllableBomb>().radius      = 0;
                    boom.GetComponent <ControllableBomb>().randomDelay = 0;
                    boom.AddComponent <TimedSelfDestruct>();
                    boom.GetComponent <ControllableBomb>().ExplodeMessage();
                }
                return;
            }


            Vector3 RelativeVelo = this.transform.InverseTransformDirection(this.rigidBody.velocity);

            this.rigidBody.AddRelativeForce(new Vector3(RelativeVelo.x * -15, RelativeVelo.y * -15, 0));
            HPCalculation(MinimumAccelerationSqrToTakeDamage);
            PositionIndicator.transform.position = targetPoint;

            if (!IAmEscapingOrReturning)
            {
                if (FUcounter >= 1000)
                {
                    FUcounter    = 0;
                    IAmSwitching = true;
                    TargetSelector();
                }
                else if (FUcounter % 50 == 0)
                {
                    Vector3 velo = Vector3.zero;
                    if (currentTarget)
                    {
                        if (currentTarget.GetComponent <Rigidbody>())
                        {
                            velo = currentTarget.GetComponent <Rigidbody>().velocity;
                        }
                    }
                    targetVeloAveraged = Vector3.Lerp(targetVeloRecorder, velo, 0.5f);
                    targetVeloRecorder = velo;
                }
            }
            else if (this.transform.InverseTransformPoint(targetPoint).sqrMagnitude <= 100 && DroneAIType.Value == 1)
            {
                IAmEscapingOrReturning = false;
                FUcounter    = 0;
                IAmSwitching = false;
                TargetSelector();
            }

            if (FUcounter % 350 == 0)
            {
                if ((PreviousPosition - this.transform.position).sqrMagnitude <= 425 && DroneAIType.Value == 1)
                {
                    IAmEscapingOrReturning = false;
                    FUcounter    = 0;
                    IAmSwitching = false;
                    TargetSelector();
                    this.rigidBody.AddRelativeForce(new Vector3(UnityEngine.Random.Range(-700, 700), 500, UnityEngine.Random.Range(-700, 700)));
                }
                PreviousPosition = this.transform.position;
            }
            if (IncomingDetection == null)
            {
                IncomingDetection      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                IncomingDetection.name = "IncomingDetection";
                IncomingDetection.transform.position = this.transform.position;
                //IncomingDetection.GetComponent<SphereCollider>().radius = SphereSize;
                //IncomingDetection.GetComponent<Renderer>().material = new Material(Shader.Find("Transparent/Diffuse"));
                //IncomingDetection.GetComponent<Renderer>().material.color = new Color(0.5f, 0, 0, 0.5f);

                Destroy(IncomingDetection.GetComponent <Renderer>());
                //Destroy(IncomingDetection.GetComponent<Rigidbody>());
                IDS          = IncomingDetection.AddComponent <IncomingDetectionScript>();
                IDS.Main     = this.GetComponentInChildren <MeshCollider>();
                IDS.MainMain = this;


                //IncomingDetection.AddComponent<Rigidbody>();
                IncomingDetection.GetComponent <SphereCollider>().isTrigger = true;
                //IncomingDetection.GetComponent<SphereCollider>().center = Vector3.up * -SphereSize;
            }
            IncomingDetection.transform.localScale = Vector3.one * SphereSize * 2;
            IncomingDetection.transform.rotation   = this.transform.rotation;
            IncomingDetection.transform.position   = Shooter.transform.position;
            IDS.SphereSize = SphereSize;

            if (IAmEscapingOrReturning)
            {
                IgnoreIncoming = !IAmEscapingOrReturning;
            }

            if (DroneAIType.Value == 1)
            {
                WhatComputerWillDo();
            }
            else
            {
                WhenAssisting();
            }

            前一帧速度 = rigidBody.velocity;

            SphereSize = Mathf.Max(15, rigidBody.velocity.magnitude);
        }