Transform.rigidbody not working on subsequent LoadLevel calls

Gday all,

I am having a massive amount of trouble with one seemingly easy part of my game.
I have the basics working perfectly however one part of the script seems to malfunction once a level has been unloaded…
The basic idea is you press the fire key and it launches a projectile based on a direction and power (standard fare there).

I have worked out it is the transform.rigidbody.xxx part that is not working. Code is below

		if ((Input.GetKeyUp(KeyCode.F))||(Input.GetMouseButtonUp(0))){
			Destroy(lineRenderer);
			notStarted = false;
	//		transform.rigidbody.velocity = dir * power; 
			transform.rigidbody.AddRelativeForce(dir * power*forcePowerModifier);
			Debug.Log("HERE!");
		}

The first time you load the level it works perfectly. It fires off a projectile which is tracked then destroyed. A new one is then created at the start point and it goes on from there - no issues so far, that can continue indefinitely with no issues.

If you return to the main menu or load a new level however… it refuses to fire. The script gets to the “HERE!” part no worries but nothing happens. I have tried using transform.position = xxx to make sure it can be manipulated and it works fine… It is getting created initially and everything works up to the firing part.

Also, the projectile has a particle system attached which works perfectly on the initial load but also fails on subsequent loading… I have removed it and it has no effect on the overall problem though.

There are no variables that are carried over from level to level… just literally LoadLevel(x)… I have no idea why this isnt working, if anyone can shed some light on it I would be VERY appreciative!

I can provide more of the code or a short video clip of the malfunction if it would help.

VERY much appreciated!!!

You could be mutating a projectile prefab (instead of the instance of it) by mistake. Something like:

GameObject p1 = Instantiate(bulletPF, pos, rotate);
bulletPF.rigidbody ....

This sort of thing often breaks every shot past the first. Possible the particular way you spawn just happens to work for one level. But then when you reload, the mangled prefab causes the problem.

Solved!

To load a new menu you press escape which opened the standard game menu. When this happens, I had used Time.timeScale = 0 to pause the game… Pressing escape again would unpause it.

This meant if you used the escape menu to get back to the main menu, timeScale was still set to 0… All fixed now!