- Home /
An instance of type 'TurretControl' is required to access non static member 'Shoot'.
I'm fairly new to Unity 3D and game programming (high school class). I tried to "make" a game outside of the classroom...and it isn't WORKING If you haven't seen the TornadoTwin tutorials then just know that there are turrets and a worm made out of 3 sphere game objects. Both shoot a fireBall.
After the last turret is destroyed (for now there is only 1) I want it to go to the next level. When I added the part that said to go to the next level and destroyed the turret Destroy(gameObject [the turret]) stopped working and the above error came up. I got rid of this component as a result. Since I got rid of that the turret continues to shoot before the new level loads. I want to stop that function which is in a different script(Turret Control) or disable/remove the script entirely at this point.
How should I go about fixing this? Anything with // was gotten rid of due to the error I stated and this error as well:No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '(function(Object): void)' was found.
Turret Collision Script or script reffering to other script:
var fireSound : AudioClip; var script: TurretControl;
function OnTriggerEnter( hit : Collider) { if(hit.gameObject.tag == "wormProjectile") { Destroy(hit.gameObject); var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity); //Destroy(gameObject); //script = GetComponent(TurretControl.Shoot); // Destroy(script.Shoot) yield WaitForSeconds (4); Application.LoadLevel("2Scene"); } }
//function Update () //{ //if(GetComponent(TurretControl)) //{ // Destroy (GetComponent(TurretControl.Shoot ())); //} //}
Reffered script or TurretControl Script:
function Shoot(seconds) { if(seconds!=savedTime)
{
var bullet = Instantiate(bulletPrefab,transform.Find("spawnPoint1").transform.position,Quaternion.identity); bullet.gameObject.tag = "enemyProjectile"; bullet.rigidbody.AddForce(transform.forward * 1000); savedTime = seconds;
}
}
Answer by Ahmer · Dec 12, 2010 at 07:06 AM
I have seen the TT's tutorial on worminator... here's my suggestion to you...
Create an Empty GameObject (_GameManager)
Create a manager Script, responsible for changing level and managing health etc.
attach a line of code in your turret that every time its destroyed a Global variable such as countTurret -= 1 in your _GameManager script.
When the variable countTurret = 0 then Application.LoadLevel(NextLevel);
I hope that gave u an idea...
That sounds like a good idea. I'll try it.Unfortunately I can't play my game/load my scene now b/c this error came up: Invalid editor window UnityEditor.GameView UnityEditor.EditorApplication:Internal_PlaymodeStateChanged(). I'll use your suggestion as a base and put it into the scene for when I fix this new problem. Again, thanks a lot! Really appreciate it!
$$anonymous$$ind taking a look at my other question too? Question: Unity suddenly stopped working when I pressed play/the problem I stated in the above comment. Thanks again again.
that was a great idea i actually never thought of doing something like that thanks for the input!