武器攻击检测问题
unity3d吧
全部回复
仅看楼主
level 7
子曦199107 楼主
void Update () {
if (Input.GetMouseButtonDown (0)) {
startPosition = transform.position;
hit = Physics.OverlapSphere (startPosition, 1.0f, 1);
{
for(int i=0;i<=hit.Length-1;i++)
{
if(hit[i].tag=="Enemy")
{
EnimyAIContoller enemy=hit[i].transform.GetComponent<EnimyAIContoller>();此处问题?
if(enemy) // 此处有问题。。。。。。。。。。。。。。。
{
enemy.state=EnimyAIContoller.currentState.die;
enemy.ani.Play("die2");
GameObject.Destroy(enemy);
}
break;
}}}}}}
为什么EnimyAIContoller enemy=hit[i].transform.GetComponent<EnimyAIContoller>();这句话有的时候会有
NullReferenceException: Object reference not set to an instance of an object
AttackTest.Update () (at Assets/_Script/AttackTest.cs:35)
这样的问题???不能每次都引用成功
用了一个if语句进行检测时,不再有错误了,但是会导致武器攻击检测很不理想。有时武器攻击会正常,但是大部分时候不能正常工作。
2014年04月10日 11点04分 1
1