Level working initially but not on subsequent Loadlevel

Gday all,

This is a mirror of a question I asked at unity answers but it seems there is more activity here…
Original post : Transform.rigidbody not working on subsequent LoadLevel calls - Questions & Answers - Unity Discussions

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!!!

well from the looks of what you got so far maybe you don’t have enough power in your variables? like power and forcepower maybe it’s not enough? unless you have other scripts that are probably destroying it., now on the other hand a video would probably help. if you put it on youtube i’ll probably be one of the first people to see it anyhow since i normally see others posts in there.

Video of the problem:

https://dl.dropbox.com/u/74159983/bandicam%202012-11-20%2008-46-46-404.avi

It is working fine initially… just the subsequent loading doesnt work?? (It is firing from mouseclick in the video)

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!