0
点赞
收藏
分享

微信扫一扫

HarmonyOS NEXT:实现电影列表功能展示界面

罗子僧 2024-10-02 阅读 14

本案例的实现流程图 

 

地形和模型 

为地形添加导航网格表面组件,方便以后寻路控制

为士兵添加动画,碰撞器,导航代理和士兵脚本组件,同时以空物体作为父节点,添加选中特效(话说这些模型怎么这么眼熟😋)

编写士兵单位脚本

目前需要什么?请看下图

上代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class SoliderObj : MonoBehaviour
{
private Animator animator;
private NavMeshAgent agent;
private GameObject footEEffect;

private void Start() {
//初始化变量
animator = GetComponentInChildren<Animator>();
agent = GetComponent<NavMeshAgent>();
footEEffect = transform.Find("FootEffect").gameObject;
//默认光圈不显
SetFootEffect(false);
}
//移动方法
public void SoliderMove(Vector3 target)
{
agent.SetDestination(target);
}

//切换动画
public void SwitchAnimator()
{
animator.SetBool("S2W",agent.velocity.magnitude>0.1);
}
//切换光圈显隐
public void SetFootEffect(bool b)
{
footEEffect.SetActive(b);
}

}
举报

相关推荐

0 条评论