【发布时间】:2017-09-11 22:08:22
【问题描述】:
你好,我正在开发一款 RTS 游戏,所以我将控制超过 1 个奴才,但我尝试添加另一个奴才并命令他们两个都直奔主题,然后他们像这样看着对方 http://imgur.com/a/uHwjG。 小兵移动的代码是这样的:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class moveTest : MonoBehaviour {
NavMeshAgent navAgent;
// Use this for initialization
void Start () {
navAgent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
move();
}
void move()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonDown(1))
{
if (Physics.Raycast(ray, out hit, 1000))
{
navAgent.SetDestination(hit.point);
}
}
}
}
【问题讨论】:
标签: c# unity3d artificial-intelligence