C# 如何在unity 3D中更改对象的坐标

C# 如何在unity 3D中更改对象的坐标,c#,unity3d,C#,Unity3d,最近,我在学习unity 3d,我想让一个物体移动C#的距离,我不知道我是否正确,这就是我写的: using UnityEngine; using System.Collections; public class sceneTransform : MonoBehaviour { public float speed=0.1f; // Use this for initialization void Start () { } // Update is

最近,我在学习unity 3d,我想让一个物体移动C#的距离,我不知道我是否正确,这就是我写的:

using UnityEngine;
using System.Collections;

public class sceneTransform : MonoBehaviour {

    public float speed=0.1f;
    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
        if(transform.position.z<7){
            transform.position += new Vector3 (0.2,0,0)*speed*Time.deltaTime;
        }
    }
}
使用UnityEngine;
使用系统集合;
公共类场景转换:单行为{
公共浮子速度=0.1f;
//用于初始化
无效开始(){
}
//每帧调用一次更新
无效更新(){
关于误差的if(变换位置z:

Assets/Scripts/sceneTransform.cs(15,68):错误CS1502:UnityEngine.Vector3.Vector3(float,float,float)”的最佳重载方法匹配具有一些无效参数,而Assets/Scripts/sceneTransform.cs(15,68):错误CS1503:Argument“#1”无法将“double”表达式转换为类型“float”

在Unity3D中使用浮动时,需要在其后面加上“f”,如:

Vector3(0.2f,0f,0f);
关于错误:

Assets/Scripts/sceneTransform.cs(15,68):错误CS1502:UnityEngine.Vector3.Vector3(float,float,float)”的最佳重载方法匹配具有一些无效参数,而Assets/Scripts/sceneTransform.cs(15,68):错误CS1503:Argument“#1”无法将“double”表达式转换为类型“float”

在Unity3D中使用浮动时,需要在其后面加上“f”,如:

Vector3(0.2f,0f,0f);

Vector3的参数必须是浮点型

transform.position += new Vector3 (0.2f,0,0) * speed * Time.deltatime;

Vector3的参数必须是浮点型

transform.position += new Vector3 (0.2f,0,0) * speed * Time.deltatime;

我总是只使用
transform.Translate()
通常为我移动对象。

我总是只使用
transform.Translate())
通常会为我移动对象。

您能更详细地解释一下您的代码是如何失败的吗?您是否尝试过显著提高
速度,因为此时您的对象将移动得非常非常非常慢?调试时,它会出错:Assets/Scripts/sceneTransform.cs(15,68):错误CS1502:与“UnityEngine.Vector3.Vector3(float,float,float)”匹配的最佳重载方法具有一些无效参数,并且Assets/Scripts/sceneTransform.cs(15,68):错误CS1503:参数“#1”无法将“double”表达式转换为类型“float”你能更详细地解释一下你的代码是如何失败的吗?你有没有尝试过显著地提高
速度
,因为此时你的对象将移动得非常非常非常慢?在调试时,它会出现错误:Assets/Scripts/sceneTransform.cs(15,68):错误CS1502:与“UnityEngine.Vector3.Vector3”匹配的最佳重载方法(float,float,float)”有一些无效参数,Assets/Scripts/sceneTransform.cs(15,68):错误CS1503:参数“#1”无法将“double”表达式转换为“float”类型谢谢您的回答帮助我解决问题。谢谢您的回答帮助我解决问题。