1 usingUnityengine;2 usingSystem.Collections;3 4 Public classAirandmove:monobehaviour5 {6 floatStopTime;7 floatMovetime;8 floatVel_x, vel_y, vel_z;//Speed9 /// <summary>Ten ///Maximum and minimum flight limits One /// </summary> A floatMaxpos_x = -; - floatMaxpos_y = -; - floatMinpos_x =- -; the floatMinpos_y =- -; - intCurr_frame; - intTotal_frame; - floatTimeCounter1; + floatTimeCounter2; - //int max_flys = n; + //Use this for initialization A voidStart () at { - Change (); - } - - //Update is called once per frame - voidUpdate () in { -TimeCounter1 + =Time.deltatime; to if(TimeCounter1 <movetime) + { -Transform. Translate (vel_x, Vel_y,0, space.self); the } * Else $ {Panax NotoginsengTimeCounter2 + =Time.deltatime; - if(TimeCounter2 >stoptime) the { + Change (); ATimeCounter1 =0; theTimeCounter2 =0; + } - } $ Check (); $ } - voidChange () - { theStopTime = Random.range (1,5); -Movetime = Random.range (1, -);Wuyivel_x = Random.range (1,Ten); theVel_y = Random.range (1,Ten); - } Wu voidCheck () - { About //If you reach the preset boundary position value, change the speed direction and let its current coordinate position be equal to the position value of the critical edge. $ if(Transform.localposition.x >maxpos_x) - { -vel_x =-vel_x; -Transform.localposition =NewVector3 (maxpos_x, TRANSFORM.LOCALPOSITION.Y,0); A } + if(Transform.localposition.x <minpos_x) the { -vel_x =-vel_x; $Transform.localposition =NewVector3 (minpos_x, TRANSFORM.LOCALPOSITION.Y,0); the } the if(Transform.localposition.y >maxpos_y) the { theVel_y =-vel_y; -Transform.localposition =NewVector3 (transform.localposition.x, Maxpos_y,0); in } the if(Transform.localposition.y <minpos_y) the { AboutVel_y =-vel_y; theTransform.localposition =NewVector3 (transform.localposition.x, Minpos_y,0); the } the } +}
AI: Deterministic AI