2D相机移动脚本引发CS0428错误

3

我正在尝试使相机在按下WASD或箭头键时移动,但它会抛出以下错误:

错误 CS0428:无法将方法组“GetComponent”转换为非委托类型“Transform”。你是否打算调用该方法?

这是发生在此脚本中的:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cameramover : MonoBehaviour
{        
    public Camera controlled;
    Vector3 movement;

    void Start()
    {
        Transform transform1 = controlled.GetComponent<Transform>;
    }

    void Update() 
    { 
        movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f);

    }
}

我尝试调用该方法,但是出现了CS0201错误,于是我试着这样做: new Transform(controlled.GetComponent<Transform>;) 但仍然没有成功,因此我来这里寻求帮助。

1个回答

1

在Game Dev Network的Discord服务器上得到了热心人的帮助,我只需要在controlled.GetComponent末尾添加一对括号即可解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接