塔防游戏-敌人控制

1.自己写

  1. 移动方向
  2. 角色朝向
  3. 销毁

移动方向
给敌人添加 CharactorControl控件
Awake()中获取
Upate()中设置运动方向(指被减、单位化)
角色朝向
敌人水平看向目标点,设置lookpos.y = transform.position.y;
销毁
如果物体的距离和目标点的距离小于10,那么目标点序号➕1,如果序号大于路径点数量则销毁物体

using UnityEngine;
using System.Collections;

public class MyEnemyControl : MonoBehaviour {
    public float m_fMoveSpeed;
    CharacterController cc;
    private int m_nCurrentPointIndex = 0;
    private Vector3 suDir;
    private Vector3 lookpos;

    void Awake(){
        cc = gameObject.GetComponent<CharacterController>();
    }
    void Update(){
        suDir = (MyPathManager.points [m_nCurrentPointIndex].position - transform.position).normalized;
        suDir.y = transform.position.y;
        lookpos = MyPathManager.points [m_nCurrentPointIndex].position;
        lookpos.y = transform.position.y;
        transform.LookAt (lookpos);
        cc.SimpleMove (suDir * Time.deltaTime * m_fMoveSpeed);
        if (Vector3.Distance(transform.position,MyPathManager.points [m_nCurrentPointIndex].position)<10) {
            m_nCurrentPointIndex++;
            if (m_nCurrentPointIndex>=MyPathManager.points.Length) {
                DestroyImmediate(this.gameObject);
            }
        }
    }

2.使用iTween

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值