My GameObject doesn't respond to anything
I've got a Unity XR project that I'm working on but I'm having issues with throwable projectiles. It was just working perfectly fine, the only issue I was having was that it was not sending damage. Now when I click play to test it, the object just doesn't do anything. The projectile is just a game object with a few components and a few child particle systems inside for visuals but not even those show up.
My script also has some explosion physics which was working fine until this weird issue where the object just chooses to not exist.
I am using the VR Interaction Framework from Bearded Ninja Games for most of the interactions and my projectile script interacts with the Damageable type from the framework. (It's a brilliant framework to jump start a VR project)
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);
}
}
}
}
}
What I've Tried:
Restarting Unity
Restoring the script to a point where it was working correctly
Putting the script onto another game object
Using a backup of the prefab from when it was working
Checking if the object was being destroyed pre-maturely
Checking if the object disappears from the hierarchy or scene
I did import the prefab and projectile script into a new project and they worked properly so I'm not sure if there's some kind of project setting or something that could be causing the issue
Answer by unity_yi4IzX0fVBTBFg · Jun 29, 2021 at 10:54 AM
Ended up just making a new unity project and importing all of my assets. It's working now but that issue is still confusing me
Your answer
Follow this Question
Related Questions
Setting a gameObject active when a button is pressed 2 Answers
Gear VR Loading screen freeze 0 Answers
RigidBody Cube flying up in the air 2 Answers
Jacks game Simulator 0 Answers
Unity VR - Held object lags behind hand position when moving. 2 Answers