错误 CS0176:无法使用实例引用访问成员“Camera.main.current";使用类型名称来限定它,而不是在 unity c# 中 [英] error CS0176: Member 'Camera.main.current' cannot be accessed with an instance reference; qualify it with a type name instead in unity c#

查看:75
本文介绍了错误 CS0176:无法使用实例引用访问成员“Camera.main.current";使用类型名称来限定它,而不是在 unity c# 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在按下 LeftMouseButton 时在鼠标位置创建一个游戏对象的实例,我试图将其转换为世界位置,但我收到一个错误:成员Camera.main.current"无法使用实例参考;用类型名称来限定它

Im trying to make a instance of a GameObject at the position of the mouse when LeftMouseButton is pressed ,im trying to convert it to world position but i get a error : Member 'Camera.main.current' cannot be accessed with an instance reference; qualify it with a type name instead

public GameObject tower;  
   public Camera sceneCamera;
   Vector3 objectP;   
    void Update () 
     {
        sceneCamera = Camera.main;
        if (sceneCamera!= null) 
        {
            Vector3 mousePos = Input.mousePosition;
         mousePos.z = 2.0f;
        Vector3 objectP = Camera.main.current.ScreenToWorldPoint(mousePos);
        }
         
     if (Input.GetButtonDown("Fire1")) 
         {
         Instantiate(tower,objectP, Quaternion.identity);
         }
     }
    
   
}

我在 c# 中相对较新,这并不紧急,但请帮助,如果我犯了一个愚蠢的错误,抱歉.谢谢!

Im relatively new in c# ,It's not urgent but please help ,sorry if i made a dumb mistake . Thanks!

推荐答案

Camera.main.current 替换为 Camera.main.

maincurrent 都是 Camera 类的静态属性,所以像你这样链接它们是没有意义的做(实际上是不允许的).

main and current are both static properties of the Camera class, so it doesn't make sense to chain them like you're doing (and is, in fact, disallowed).

这篇关于错误 CS0176:无法使用实例引用访问成员“Camera.main.current";使用类型名称来限定它,而不是在 unity c# 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆