So I have a character who is supposed to send out a shockwave, thus pushing physics objects around him. I was using the addexplosionforce bit in Unity, and figured out that the explosion for needs to be on the objects I want effected by the explosion (I put it on the player himself the first time, and of course, sent him skyrocketting every time I pressed the shockwave key!)
So I have these blocks with the explosion code, but now I’m having issues gaining access to the variables for the shockwave I set up in the player class. Here is my code for the explosion, located on the prefab of the physics cubes that I want to move: (ignore the “canDust” variable, that’s for something else.
void Start ()
{
canDust = true;
blip = GameObject.Find("player_Blip");
}
// Update is called once per frame
void Update ()
{
Vector3 explosionPos = blip.transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius, 3);
foreach (Collider hit in colliders)
{
if (!hit)
{
continue;
}
if (hit.rigidbody)
{
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3);
}
}
}
So when the blocks are instantiated by the game, they find the player object. The explosion happens from the players position, which is exactly what I want. Now, I want to be able to change the radius and the power bits with the radius and power of the explosion that is set in public variables in the player class.
So, in summary, once I find the object I want, how do I access it’s variables? Any help is GREATLY appreciated! Thanks!