这是我的代码 Unity 说-“意外的符号 {”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera : MonoBehaviour {
//variables
public Transform player;
public float smooth = 0.3f;
private Vector3 velocity = Vector3.zero; //camera velocity to zero with variable velocity
//Methods
void Update()
{
Vector3 pos = new Vector3();
pos.x = player.position.x; // postion on x axis = player
pos.z = player.position.z - 7f; //-7f to move the camera a little back from player position
pos.y = player.position.y;
transform.position = Vector3.SmoothDamp{ transform.position, pos,ref velocity, smooth};
//smoothdamp is a function of vector 3 which smoothenes the movement
}
}
鲁弗斯 L 是正确的。
您在 SmoothDamp 方法中使用了大括号而不是括号,请在此处查看如何使用它https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
在 C# 中,我们使用大括号来显示属于语句的代码块,例如 if 块、using 块、方法块、类块等。
大括号也用于对象实例化(当构造函数被调用时)来初始化变量,例如
Person john = new Person(){ Name = "John" };
简而言之,大括号定义范围,其中定义的值在大括号终止时超出范围,除非这些值存在于其他地方。
然而,括号用于多个其他事物,但没有一个表示范围。它们用于指示参数、转换、改变数学表达式出现的顺序等。https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/invocation-operator
总之,注意不要混淆 () 和 {}+
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句