我正在与AI敌人一起制作fps游戏,但出现了此错误,我不知道错误在哪里 是因为它写(在<9061962f637f4c89b5332c95b2cf7751>:0)
我并不着急,真正的问题是我找不到错误的出处,因为它没有说,如果您可以告诉我它在哪里,那就太好了。非常感谢可以提供帮助的每个人。
这是完整的错误(实际上相当长):
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at <9061962f637f4c89b5332c95b2cf7751>:0)
UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List1[T] inEdges, System.Collections.Generic.List
1[T] ok, System.Collections.Generic.List`1[T] error, System.Boolean inEdgesUsedToBeValid) (at <9061962f637f4c89b5332c95b2cf7751>:0)
UnityEditor.Graphs.Graph.WakeUpEdges (System.Boolean clearSlotEdges) (at <9061962f637f4c89b5332c95b2cf7751>:0)
UnityEditor.Graphs.Graph.WakeUp (System.Boolean force) (at <9061962f637f4c89b5332c95b2cf7751>:0)
UnityEditor.Graphs.Graph.WakeUp () (at <9061962f637f4c89b5332c95b2cf7751>:0)
UnityEditor.Graphs.Graph.OnEnable () (at <9061962f637f4c89b5332c95b2cf7751>:0)
我在这里放置了一些我认为可能有问题的代码:
第一个脚本:
using UnityEngine;
using System.Collections;
using System.Globalization;
using UnityEngine.UI;
public class GunShoot : MonoBehaviour
{
public int damage = 10;
public float range = 100f;
public float fireRate = 15f;
public float impactForce = 30f;
public int maxAmmo = 10;
private int currentAmmo;
public float reloadTime = 1f;
private bool isReloading = false;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
public Text ammoCounter;
public Animator animator;
private float nextTimeToFire = 0f;
void Start()
{
currentAmmo = maxAmmo;
}
void OnEnable()
{
isReloading = false;
animator.SetBool("Reloading", false);
}
// Update is called once per frame
void Update()
{
if (isReloading)
return;
if (currentAmmo <= 0)
{
StartCoroutine(Reload());
return;
}
if (Input.GetKeyDown(KeyCode.R))
{
if (currentAmmo <= maxAmmo)
{
StartCoroutine(Reload());
return;
}
}
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
ammoCounter.text = currentAmmo.ToString() + "/" + maxAmmo;
}
IEnumerator Reload()
{
isReloading = true;
animator.SetBool("Reloading", true);
yield return new WaitForSeconds(reloadTime - .25f);
animator.SetBool("Reloading", false);
yield return new WaitForSeconds(.25f);
currentAmmo = maxAmmo;
isReloading = false;
}
void Shoot()
{
muzzleFlash.Play();
currentAmmo--;
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Enemy target = hit.transform.GetComponent<Enemy>();
if (target != null)
{
hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGO, 0.6f);
}
}
}
第二个脚本:
using System;
using UnityEngine;
public class CharacterStats : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth { get; private set; }
public Stat damage;
public Stat armor;
void Awake()
{
currentHealth = maxHealth;
}
void Update()
{
}
public void ApplyDamage (int damage)
{
damage -= armor.GetValue();
damage = Mathf.Clamp(damage, 0, int.MaxValue);
currentHealth -= damage;
if (currentHealth <= 0)
{
Die();
}
}
public virtual void Die()
{
}
}
非常感谢你