c# - 错误 CS1022:类型或命名空间定义,或统一预期的文件结尾
问题描述
我有一个在 Unity 中无法解决的错误。
这样做(我认为)是在点之间移动平台。
我刚刚在这里放了一些文字,所以我实际上可以发布这个......为什么堆栈溢出会这样做。
这是错误:
Assets\Scripts\Mover.cs(74,1):错误 CS1022:类型或命名空间定义,或预期文件结尾
这是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour {
public Vector3[] points;
public int point_number = 0;
private Vector3 current_target;
public float tolerance;
public float speed;
public float delay_time;
private float delay_start;
public bool automatic;
// Start is called before the first frame update
void Start()
{
if(points.lengh > 0)
{
current_target = 0;
}
time = speed * Time.deltaTime;
}
}
// Update is called once per frame
void Update()
{
if(transform.position != current_target)
{
MovePlatform();
}
else
{
UpdateTarget();
}
}
void MovePlatform()
{
Vector3 heading = current_target - transform.position;
transform.position += (heading / heading.magnitude) * speed * time.deltaTime;
if(heading.magnitude = tolerance)
{
transform.position = current_target;
delay_start = Time.time;
}
}
void UpdateTarget()
{
if(automatic)
{
if(Time.time - delay_start > delay_time)
{
NextPlatform();
}
}
}
public void NextPlatform()
{
point_number ++;
if(point_number >= points.Length)
{
point_number = 0;
}
current_target = points[point_number];
}
}
解决方案
看起来你的 start 函数中有一个额外的 curley 会弄乱你的代码
void Start()
{
if(points.lengh > 0)
{
current_target = 0;
}
time = speed * Time.deltaTime;
}
}
— 删除最后一个卷曲
推荐阅读
- android - 多个活动的导航抽屉,无需选择导航抽屉活动
- kubernetes - 在代理服务器后面运行 BookInfo 示例失败,调用 webhook “pilot.validation.istio.io”失败
- javascript - 直接通过其 id 访问元素时的扩展问题,而不是 getElementById
- c++ - “ostream &os”有什么用?
- stripe-payments - 如何从 Stripe 向我的客户卡汇款?
- javascript - vuetify v-select 值在 Created 和 onChange 上是否不同?
- javascript - 创建一个 java 脚本函数来进行 api 调用并检索数据
- algorithm - 求未加权无向图的直径
- pyspark - 读取存储在 HDFS 中的模型(.pkl 和 .scl)文件
- python - 如何将 HEX 的第一个零附加到 BIN 字符串?