this kinda works (not ideal) to let the player ONLY fire 1 ball (which is what I wanted). Onto my problem:
Using this script (on my floor) destroys the ball when the player misses and it hits the floor:
function OnCollisionEnter ( collision : Collision) {
if (collision.collider.name == “Bullet”)
Destroy (GameObject.Find(“Bullet”));
}
The problem I have is that once the ball is destroyed for the first time (after hitting the floor) I can’t fire any more at all. I don’t know what to add to the shooting script to make it allow the player to fire again (just one ball at a time again)
Ok, that was a big pain. Have to rewrite everything again. At least I know what I'm going to be writing.
Haven't tested your scripts out, but they are fine. The problem is in the logic of the code. In the update() function, when ever a second bullet is created it adds to the var MaxObjectCount, however when it gets to 2 then in the checkhit() function, the last object to be created will be destroyed. Now here is the important part, in the check()after destroying the object they decrease the value of MaxObjectCount by one. Your collision check on the floor does not do that. So what happens is that when the bullet hits the floor MaxObjectCount become 2. This means that when you try to fire the next time check() will be called and destroy the object imdeiatlly. At least that is how I understand it.
So what you need to do is to update the variable from the collision check function.
//This is the object that has the shoot script on it.
var shootObject : GameObject;
function OnCollisionEnter ( collision : Collision) {
if (collision.collider.name == "Bullet"){
//replace both 'ScriptName' with the name of the script that has your code in it.
var shootScript : ScriptName = shootObject.GetComponent(ScriptName);
Destroy (GameObject.Find("Bullet"));
//modifies the var.
shootScript.MaxObjectCount -= 1;
}
}
Hopefully I didn't mess it up this time around. Someone will have to speak up if I forgot something.
As I said haven't tested anything, though that should fix your problem. If it doesn't then I'll test out all the scripts when I have the time.