【发布时间】:2023-02-10 23:26:48
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankScopeScript : MonoBehaviour
{
public float speed;
private float waitTime;
public float startWaitTime;
public Transform[] moveSpots;
private int randomSpot;
void Start()
{
randomSpot = Random.Range(0, moveSpots.Length);
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, moveSpots[randomSpot].position, speed * Time.deltaTime);
if (Vector3.Distance(transform.position, moveSpots[randomSpot].position) < 0.2f)
{
if (waitTime <= 0)
{
randomSpot = Random.Range(0, moveSpots.Length);
waitTime = startWaitTime;
}
else
{
waitTime -= Time.deltaTime;
}
}
}
}
想使用 transform.LookAt(randomSpot) 但我不能...使用 int 进行转换时出错,请帮助我... 我试图随机创建公共转换;并赋值randomSpot,但是,又报错
【问题讨论】: