前边我们的玩家对象已经能够发出子弹,现在我们要创建敌人
现在创建对象已经比较熟练,直接创建Cube对象作为敌人命名为Enemy。为敌人对象创建脚本ReactiveTarget用来响应玩家击中。
检测是否击中目标对象
RayShooter.cs
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
GameObject hitObject = hit.transform.gameObject;
ReacticeTarget target = hitObject.GetComponent<ReacticeTarget>();
if (target != null)
{
target.ReactToHit();
}
StartCoroutine(SphereIndicator(hit.point));
}
被击中处理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReacticeTarget : MonoBehaviour {
public void ReactToHit() {
StartCoroutine(Die());
}
private IEnumerator Die() {
this.transform.Rotate(-75, 0, 0);
yield return new WaitForSeconds(1.5f);
Destroy(this.gameObject);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
下一篇,给予敌人AI逻辑
游戏图示、游戏下载、源码下载http://blog.youkuaiyun.com/d276031034/article/details/56016801