这是完整的错误:
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++;
}
}
}
答案 0 :(得分:1)
GameObject.FindObjectOfType()需要查找对象类型。你没有定义和对象类型?尝试添加GUItexture等类型。
代码如下:
GameObject.FindObjectOfType(typeof(GUITexture))
而不是:GameObject.FindObjectOfType();