c# - 不可调用的成员“Vector3”不能像方法一样使用。Wander Ai 脚本出错
问题描述
我已经为我的敌人 AI 统一编写了代码,以便在自上而下的游戏中四处游荡。我是 C# 的新手,因此完成这项工作并理解所有内容对我来说非常复杂。在这里,我做了所有我能做的并解决了大部分错误,但我找不到这个错误的解决方案。请帮忙!!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomRoaming : MonoBehaviour
{
public float moveSpeed = 5f;
public Vector3 wayPoint;
public float Range = 10;
// Start is called before the first frame update
void Start()
{
Wander();
}
// Update is called once per frame
void Update()
{
transform.position += transform.TransformDirection(Vector3.forward) * moveSpeed * Time.deltaTime;
if ((transform.position - wayPoint).magnitude < 3)
{
Wander();
}
}
void Wander() {
wayPoint = Vector3(Random.Range(transform.position.x - Range, transform.position.x + Range), 1, Random.Range(transform.positon.y - Range, transform.position.y + Range));
wayPoint.z = 0;
transform.LookAt(wayPoint);
Debug.log(wayPoint + "and" + (transform.postion - wayPoint).magnitude);
}
}