首页 > 解决方案 > 错误 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];
    }
}

标签: c#unity3d

解决方案


看起来你的 start 函数中有一个额外的 curley 会弄乱你的代码

 void Start()
    {
         if(points.lengh > 0)
         {
            current_target = 0;
         }
         time = speed * Time.deltaTime;
       }
    }

— 删除最后一个卷曲


推荐阅读