【问题标题】:error CS0411:The type arguments for method `UnityEngine.Object.FindObjectOfType<T>()'错误 CS0411:方法“UnityEngine.Object.FindObjectOfType<T>()”的类型参数
【发布时间】:2014-12-31 05:09:07
【问题描述】:

这是完整的错误:

Assets/Scripts/BoxLauncher.cs(15,32):错误 CS0411:类型参数 对于方法“UnityEngine.Object.FindObjectOfType()”不能 从用法推断。尝试明确指定类型参数

这是我的代码:

using UnityEngine;
using System.Collections;

public class BoxLauncher : MonoBehaviour {

    public GameObject[] boxPrefabs;

    public float fireDelay = 3f;
    public float nextFire = 1f;

    public float fireVelocity = 10f;

    void FixedUpdate () {


        // This is the line that the error is pointing to.
        if (GameObject.FindObjectOfType().hasLost){
            return;
        }

        nextFire -= Time.deltaTime;

        if(nextFire <= 0) {
            // Spawn a new box!
            nextFire = fireDelay;

            GameObject boxGO = (GameObject)Instantiate( 
                        boxPrefabs[ Random.Range(0, boxPrefabs.Length)], 
                        transform.position,
                        transform.rotation
                        );

            boxGO.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);

            GameObject.FindObjectOfType<ScoreManager>().score++;
        }
    }
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    GameObject.FindObjectOfType() 需要对象类型才能找到。你没有定义和对象类型?尝试添加一种类型,例如 GUItexture。

    代码如下所示:
    GameObject.FindObjectOfType(typeof(GUITexture))
    而不是:GameObject.FindObjectOfType();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      相关资源
      最近更新 更多