C# 错误CS1061:';游戏对象';不包含';本地位置';

C# 错误CS1061:';游戏对象';不包含';本地位置';,c#,unity3d,C#,Unity3d,H、 我要开发一个与unity的拖放游戏,但是出现了这个错误,请告诉我如何修复这个错误 这是全部错误 (错误CS1061:“GameObject”不包含“localPosition”的定义,并且找不到接受“GameObject”类型的第一个参数的可访问扩展方法“localPosition”(是否缺少using指令或程序集引用?) 这是我在C#脚本中的代码 在更新函数的最后一行的最后一个参数中,您键入了this.gameObject.localPosition.z。没有名为localPositi

H、 我要开发一个与unity的拖放游戏,但是出现了这个错误,请告诉我如何修复这个错误

这是全部错误 (错误CS1061:“GameObject”不包含“localPosition”的定义,并且找不到接受“GameObject”类型的第一个参数的可访问扩展方法“localPosition”(是否缺少using指令或程序集引用?)

这是我在C#脚本中的代码


在更新函数的最后一行的最后一个参数中,您键入了this.gameObject.localPosition.z。没有名为localPosition的字段。您应该通过this.gameObject.transform.localPosition.z来修复它。总之,您的更新应该如下所示:

// Update is called once per frame
void Update()
{
    if(moving){
        Vector3 mousePos; 
        mousePos= Input.mousePosition; 
        mousePos = Camera.main.ScreenToWorldPoint(mousePos); 

        this.gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, this.gameObject.transform.localPosition.z);
    }
    
}

嗯,它不。。。你是说
这个.gameObject.transform.localPosition.z
?投票决定以打字错误为基础关闭此网站
// Update is called once per frame
void Update()
{
    if(moving){
        Vector3 mousePos; 
        mousePos= Input.mousePosition; 
        mousePos = Camera.main.ScreenToWorldPoint(mousePos); 

        this.gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, this.gameObject.transform.localPosition.z);
    }
    
}