void Start()
        {
            // Get the marker image in the scene.
            if (string.IsNullOrEmpty(Aim_Marker_Name))
            {
                return;
            }
            GameObject markerObject = GameObject.Find(Aim_Marker_Name);

            if (markerObject)
            {
                markerImage = markerObject.GetComponent <Image>();
            }
            else
            {
                // The marker cannot be found in the scene.
                Debug.LogWarning(Aim_Marker_Name + " cannot be found in the scene.");
                Destroy(this);
                return;
            }
            markerTransform = markerImage.transform;

            // Get the "Aiming_Control_CS" in the tank.
            aimingScript = GetComponent <Aiming_Control_CS>();
            if (aimingScript == null)
            {
                Debug.LogWarning("'Aiming_Control_CS' cannot be found in the MainBody.");
                Destroy(this);
            }
        }
        public override void Prepare(Aiming_Control_CS aimingScript)
        {
            this.aimingScript = aimingScript;

            // Set the "Use_Auto_Turn".
            aimingScript.Use_Auto_Turn = true;

            // Get the "Gun_Camera_CS".
            gunCameraScript = GetComponentInChildren <Gun_Camera_CS>();

            // Set the relationship.
            ID_Settings_CS idScript = GetComponentInParent <ID_Settings_CS>();

            if (idScript)
            {
                thisRelationship = idScript.Relationship;
            }

            // Set the initial aiming mode.
            aimingScript.Mode = 1; // Free aiming.
            aimingScript.Switch_Mode();

            // Set the initial target position.
            aimingScript.Target_Position = transform.position + (transform.forward * 128.0f);
        }
        void Start()
        {
            thisTransform = transform;

            // Get the reticle wheel image in the scene.
            if (string.IsNullOrEmpty(ReticleWheel_Name))
            {
                return;
            }
            GameObject reticleWheelObject = GameObject.Find(ReticleWheel_Name);

            if (reticleWheelObject)
            {
                reticleWheelImage = reticleWheelObject.GetComponent <Image>();
            }
            if (reticleWheelImage == null)
            {
                Debug.LogWarning(ReticleWheel_Name + " cannot be found in the scene.");
                Destroy(this);
                return;
            }
            reticleWheelTransform = reticleWheelImage.transform;

            // Get the gun camera in the tank.
            if (Gun_Camera == null)
            {
                Gun_Camera = GetComponent <Camera>();
            }

            // Get "Aiming_Control_CS" in the tank.
            aimingScript = GetComponentInParent <Aiming_Control_CS>();
        }
        public void Get_Aiming_Script(Aiming_Control_CS tempAimingScript)
        { // Called from "Aiming_Control_CS".
            aimingScript = tempAimingScript;

            // Update the target information.
            Update_Traget_Information();
        }
        public override void Prepare(Cannon_Fire_CS cannoFireScript)
        {
            this.cannonFireScript = cannoFireScript;

            aiScript     = transform.root.GetComponentInChildren <AI_CS>();
            turretScript = GetComponentInParent <Turret_Horizontal_CS>();
            cannonScript = GetComponent <Cannon_Vertical_CS>();
            aimingScript = GetComponentInParent <Aiming_Control_CS>();
        }
Ejemplo n.º 6
0
        void Initialize()
        {
            // Get this relationship.
            var idScript = GetComponentInParent <ID_Settings_CS>();

            thisRelationship = idScript.Relationship;

            // Get "Aiming_Control_CS" in the commander.
            commanderAimingScript = AI_Script.Settings_Script.Commander.GetComponentInChildren <Aiming_Control_CS>();
            if (commanderAimingScript == null)
            {
                AI_Script.Is_Sharing_Target = false;
                Destroy(this);
            }
        }
Ejemplo n.º 7
0
        void Start()
        {
            // Get the marker image in the scene.
            if (string.IsNullOrEmpty(Lead_Marker_Name))
            {
                return;
            }
            GameObject markerObject = GameObject.Find(Lead_Marker_Name);

            if (markerObject)
            {
                markerImage = markerObject.GetComponent <Image>();
            }
            else
            {
                // The marker cannot be found in the scene.
                Debug.LogWarning(Lead_Marker_Name + " cannot be found in the scene.");
                Destroy(this);
                return;
            }
            markerTransform = markerImage.transform;

            // Get the "Aiming_Control_CS" in the tank.
            aimingScript = GetComponent <Aiming_Control_CS>();
            if (aimingScript == null)
            {
                Debug.LogWarning("'Aiming_Control_CS' cannot be found in the MainBody.");
                Destroy(this);
            }

            // Get the "Bullet_Generator_CS".
            if (Bullet_Generator_Script == null)
            {
                Bullet_Generator_Script = GetComponentInChildren <Bullet_Generator_CS>();
            }
            if (Bullet_Generator_Script == null)
            {
                Debug.LogWarning("'Bullet_Generator_CS' cannot be found. The cannon cannot get the bullet velocity.");
                Destroy(this);
                return;
            }
            bulletGeneratorTransform = Bullet_Generator_Script.transform;
        }
        void Initialize()
        { // This function must be called in Start() after changing the hierarchy.
            thisTransform      = transform;
            parentTransform    = thisTransform.parent;
            aimingScript       = GetComponentInParent <Aiming_Control_CS>();
            currentLocalAngles = thisTransform.localEulerAngles;
            angleY             = currentLocalAngles.y;
            Max_Right          = angleY + Max_Right;
            Max_Left           = angleY - Max_Left;

            // Get the "Bullet_Generator_CS".
            if (Bullet_Generator_Script == null)
            {
                Bullet_Generator_Script = GetComponentInChildren <Bullet_Generator_CS>();
            }
            if (Bullet_Generator_Script == null)
            {
                Debug.LogWarning("'Bullet_Generator_CS' cannot be found. The cannon cannot get the bullet velocity.");
                // Set the fake value.
                bulletVelocity = 250.0f;
            }
        }
Ejemplo n.º 9
0
 public virtual void Prepare(Aiming_Control_CS aimingScript)
 {
     this.aimingScript = aimingScript;
 }
        public override void Prepare(Aiming_Control_CS aimingScript)
        {
            this.aimingScript = aimingScript;

            aimingScript.Use_Auto_Turn = false;
        }
Ejemplo n.º 11
0
        void Initialize()
        {
            thisTransform = transform;

            // Get "AI_Settings_CS" in the top object.
            Settings_Script = GetComponentInParent <AI_Settings_CS>();
            if (Settings_Script == null)
            {
                Debug.LogError("'AI_CS' requires 'AI_Settings_CS' in the top object.");
                Destroy(this);
                return;
            }

            // Get "Aiming_Control_CS".
            aimingScript = GetComponentInParent <Aiming_Control_CS>();

            // Get "AI_Eye"
            eyeTransform = thisTransform.Find("AI_Eye"); // (Note.) Do not rename "AI_Eye".
            if (eyeTransform == null)
            {
                Debug.LogError("'AI_Eye' can not be found. ");
                Destroy(this);
            }

            // Get "AI_Hand_CS" script.
            handScript = thisTransform.GetComponentInChildren <AI_Hand_CS>();

            // Get all the "Bullet_Generator_CS" in the tank.
            bulletGeneratorScripts = thisTransform.parent.GetComponentsInChildren <Bullet_Generator_CS>();

            // Instantiate NavMeshAgent object.
            GameObject agentObject;

            if (NavMeshAgent_Prefab)
            {
                agentObject = Instantiate(NavMeshAgent_Prefab, thisTransform.position, thisTransform.rotation, thisTransform.parent.parent) as GameObject;
                navAgent    = agentObject.GetComponent <NavMeshAgent>();
            }
            else
            {
                agentObject = new GameObject("AI_NavMeshAgent_Object");
                agentObject.transform.SetPositionAndRotation(thisTransform.position, thisTransform.rotation);
                agentObject.transform.parent = thisTransform.parent.parent;
                navAgent = agentObject.AddComponent <NavMeshAgent>();
            }
            navAgentTransform     = agentObject.transform;
            navAgent.acceleration = 120.0f;

            // 'Follow_Target' settings.
            if (Settings_Script.Follow_Target)
            {
                Get_Follow_Transform();
            }
            else
            { //  // The "Follow_Target" is not set.
                // Set up the waypoints.
                Set_WayPoints();
                // Set the first waypoint.
                Update_Next_WayPoint();
            }

            // 'AI_State_Text' settings.
            if (Settings_Script.AI_State_Text)
            {
                UI_AIState_Control_CS stateScript = Settings_Script.AI_State_Text.GetComponent <UI_AIState_Control_CS>();
                if (stateScript == null)
                {
                    stateScript = Settings_Script.AI_State_Text.gameObject.AddComponent <UI_AIState_Control_CS>();
                }
                stateScript.Get_AI_Script(this);
            }

            // 'Commander' settings.
            if (Settings_Script.Commander)
            {
                AI_Share_Target_CS shareTargetScript = gameObject.AddComponent <AI_Share_Target_CS>();
                shareTargetScript.AI_Script = this;
            }

            // Get the "Drive_Control_CS".
            driveControlScript = GetComponentInParent <Drive_Control_CS>();

            // Set the current max speed rate.
            currentMaxSpeedRate = Max_Speed_Rate * Settings_Script.Patrol_Speed_Rate;
        }
Ejemplo n.º 12
0
        void Update()
        {
            // Check the commander exists.
            if (AI_Script.Settings_Script.Commander == null)
            { // The commander might have been removed from the scene.
                // Stop sharing the target.
                AI_Script.Is_Sharing_Target = false;
                Destroy(this);
                return;
            }

            // Check the commander is living.
            if (commanderAimingScript == null)
            {     // The "Aiming_Control_CS" in the commander has been lost.
                if (AI_Script.Settings_Script.Commander.root.tag == "Finish")
                { // The commander has been destroyed.
                    // Stop sharing the target.
                    AI_Script.Is_Sharing_Target = false;
                    return;
                }
                else
                { // The commander has been respawned.
                    // Get "Aiming_Control_CS" again.
                    commanderAimingScript = AI_Script.Settings_Script.Commander.GetComponentInChildren <Aiming_Control_CS>();
                }
            }

            // Sharing Process
            if (AI_Script.Is_Sharing_Target)
            { // Sharing the target now.
                // Check the aiming mode of the commander.
                if (commanderAimingScript.Mode == 0)
                { // The aiming mode is "Keep the initial positon".
                    // Stop sharing the target.
                    AI_Script.Is_Sharing_Target = false;
                    AI_Script.Lost_Target();
                    return;
                }

                // Check the both tanks have the same target.
                if (commanderAimingScript.Target_Transform != null && commanderAimingScript.Target_Transform != AI_Script.Target_Transform)
                { // The commander is locking on different target.
                    // Check the target's relationship.
                    if (Check_Relationship() == true)
                    {
                        // Start sharing the new target.
                        Share_Target();
                    }
                    return;
                }

                // Check the target is living.
                if (AI_Script.Target_Transform == null || AI_Script.Target_Transform.root.tag == "Finish")
                { // The target has been removed or destroyed.
                    // Stop sharing the target.
                    AI_Script.Is_Sharing_Target = false;
                }
            }
            else
            { // Not sharing the target now.
                // Check the commander's target.
                if (commanderAimingScript.Target_Transform)
                { // The commander is locking on any target.
                    // Check the target's relationship.
                    if (Check_Relationship() == true)
                    {
                        // Start sharing the target.
                        Share_Target();
                    }
                }
            }
        }