【发布时间】: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++;
}
}
}
【问题讨论】: