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