游戏对象在加载时无响应

问题描述

我有一个正在开发的 Unity VR 项目,但我遇到了可投掷弹丸的问题。 它工作得非常好,我遇到的唯一问题是它没有造成损坏。现在,当我点击播放来测试它时,对象什么也不做。射弹只是一个游戏对象,里面有一些组件和一些用于视觉效果的子粒子系统,但甚至没有显示出来。

我的脚本也有一些爆炸物理,在这个奇怪的问题之前,对象只是选择不存在,它运行良好。

我使用 Bearded Ninja Games 的 VR 交互框架进行大部分交互,并且我的弹丸脚本与框架中的 damageable 类型交互。 (这是启动 VR 项目的绝妙框架)

Component setup for the projectile

投射物脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BNG{

    public class MagicProjectiles : MonoBehavIoUr
    {
        public float effecTradius = 5f;
        public float physicsstrength = 100f;
        public float basedamage = 20f;
        public float statModifier = 20f;
        public float damage;

        void Start()
        {
            SphereCollider collider = GetComponent("SphereCollider") as SphereCollider;
            damage = basedamage + (basedamage * statModifier / 100);
        }

        void OnCollisionEnter(Collision collision)
        {
            Debug.Log("Exploding");
            Rigidbody projectile = GetComponent("Rigidbody") as Rigidbody;
            Vector3 explosionPos = transform.position;
            Collider[] colliders = Physics.OverlapSphere(explosionPos,effecTradius);
            foreach (Collider hit in colliders)
            {
                //Debug.Log(hit);
                Rigidbody objectHit = hit.GetComponent<Rigidbody>();
                damageable damageable = hit.GetComponent<damageable>();
                if (objectHit != null)
                {
                    objectHit.AddExplosionForce(physicsstrength,explosionPos,effecTradius,3.0f);
                    if (damageable)
                    {
                        Debug.Log("Sending " + damage + " damage to " + damageable);
                        damageable.Dealdamage(damage,collision.GetContact(0).point,collision.GetContact(0).normal,true,gameObject,collision.gameObject);
                    }
                    Destroy(this,1);
                }
            }
        }
    }
}

Unity 没有给我这个脚本的任何错误

我尝试过的:

  • 重新启动 Unity
  • 将脚本恢复到正常工作的程度
  • 将脚本放到另一个游戏对象上

更新: 我什至在添加弹丸脚本之前尝试使用我的弹丸预制件的备份,但它甚至不起作用。

更新: 我创建了一个新的 Unity 项目,与脚本一起复制到弹丸预制件上,它运行得非常好。这只让我更糊涂了

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)