using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Rigidbody))]
public class spacebarImpulse : MonoBehaviour {
void Start () {
}
void Update () {
if(Input.GetKeyDown(KeyCode.Space)) {
GameObject.Find("astar").GetComponent<AstarPath>().enabled = !GameObject.Find("astar").GetComponent<AstarPath>().enabled;
GameObject[] Enemies = GameObject.FindGameObjectsWithTag("enemy");
foreach (GameObject enemy in Enemies) {
GetComponent<AIFollow>().enabled = !GetComponent<AIFollow>().enabled;
rigidbody.AddExplosionForce(10,transform.position,5);
}
}
}
}
После компиляции:
Assets/Handmade/Enemy/spacebarImpulse.cs(18,45): warning CS0219: The variable `enemy' is assigned but its value is never used
При нажатии на пробел:
NullReferenceException: Object reference not set to an instance of an object
spacebarImpulse.Update () (at Assets/Handmade/Enemy/spacebarImpulse.cs:19)