1 usingUnityengine;2 usingSystem.Collections;3 4 Public classTroll:monobehaviour5 {6 7 Private BOOLIsidel=true;8 Public floatTimer =2;9 Public intSpeed =1;Ten Privaterigidbody rigidbody; One PrivateAnimator Anim; A - - the voidStart () - { -Rigidbody = This. Getcomponent<rigidbody>(); -Anim = This. Getcomponent<animator>(); + } - + //Update is called once per frame A voidUpdate () at { -Timer-=Time.deltatime; - if(timer<=0) - { - if(Isidel) - { in //Walking Method - Transformtowalk (); to } + Else - { the * //to stand in a State $ Transformtoidel ();Panax Notoginseng } - } the if(!Isidel) + { A //to shift the //transform.position + = transform.forward*time.deltatime*speed; +Rigidbody.position + = transform.forward*time.deltatime*Speed ; - } $ $ } - - Public voidTransformtoidel () the { -Timer =2f;WuyiIsidel =true; the Animationtoidel (); - } Wu - Public voidTransformtowalk () About { $Isidel =false; -Timer =5f; - intRandom = Random.range (- -, -); -Transform. Rotate (NewVector3 (0, Random,0)); A Animationtowalk (); + } the - Public voidAnimationtowalk () $ { theAnim. SetFloat ("Walk",1.0f); theAnim. SetFloat ("Idle", 0f); theAnim. SetFloat ("Run", 0f); the } - in Public voidAnimationtoidel () the { theAnim. SetFloat ("Walk", 0f); AboutAnim. SetFloat ("Idle",1.0f); theAnim. SetFloat ("Run", 0f); the } the}
Auto-Mobile AI for enemies in 3d mode