using UnityEngine;using System.Collections;public class enemyBehaviour : MonoBehaviour{ //enemy that moves to player when close enough public float speed = 6f; public Transform player; public float enemySight = f;public AudioClip[] clips;public AudioSource source;int rand;static private int hohoindex = 8;static private int deathindex = ; // Use this for initialization void Start() {rand = Random.Range (0, hohoindex);source.clip = clips [rand]; } // Update is called once per frame void FixedUpdate() {if (!puller_control.isDead) {player = GameObject.Find ("Player").transform;//move and face towards playervar heading = player.position - transform.position;var distance = heading.magnitude;var direction = heading / distance;if (heading.sqrMagnitude < enemySight * enemySight) {float angle = Mathf.Atan2 (heading.y, heading.x) * Mathf.Rad2Deg;Quaternion q = Quaternion.AngleAxis (angle, Vector3.forward);//transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * speed);transform.position = Vector2.MoveTowards (rigidbody2D.position, new Vector2 (player.transform.position.x, player.transform.position.y), Time.deltaTime * speed);}}StartCoroutine("HoHo");}//die on collision with sledvoid OnCollisionEnter2D(Collision2D collision){if(collision.gameObject.name == "Sled"){if(collision.relativeVelocity.magnitude>3){source.Stop();source.clip = clips[Random.Range(hohoindex, deathindex)];AudioSource.PlayClipAtPoint(source.clip, this.transform.position);Destroy(this.gameObject);}}if(collision.gameObject.name == "Player"){puller_control.isDead = true;Destroy(player.gameObject);Application.LoadLevel("GameOver");}}//Coroutine to call the enemy's hohos.IEnumerator HoHo() {if (!source.isPlaying) {rand = Random.Range (0, hohoindex);source.clip = clips [rand];source.Play();yield return new WaitForSeconds(Random.Range(5, ));}}}
推荐整理分享Unity Enemy behaviour,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!
Unity KillCount usingUnityEngine;usingSystem.Collections;publicclassKillCountMult:MonoBehaviour{publicGUITextkText;publicstaticintkills1;publicstaticintkills2;publicstaticboolplayerKilled;publicstaticboolplayer2Kille
用Unity开发移动平台的游戏 不可避免的会遇到屏幕分辨率 欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频、U3D教程、U3D常见问题、U3D项目源码,【狗刨学习网】unity极致学
UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样 也许看标题比较难懂,我要表达的是这个意思:在hierarchy里面,UIroot下有个命名为MessageBox的panel,上面挂载着MessageBox脚本,脚本部分如下:publicclassMessage